Vast amounts of valuable information are locked away in unstructured text: emails, customer reviews, project reports, legal documents, and more. Getting this information into a usable, organized format like a spreadsheet or database has traditionally required manual effort or complex, custom-built software. Today, large language models (LLMs) can act as powerful, flexible tools for structured data extraction.

This guide will show you how to instruct an LLM to read through messy text and pull out the specific pieces of information you need, formatting them perfectly every time. We'll cover both a simple, no-code approach for chatbot users and a more robust method for developers building applications.
What Is Structured vs. Unstructured Data?
First, let's clarify the terms:
- Unstructured Data: Free-form text without a predefined model. Think of the body of an email or a paragraph in a report. It's easy for humans to read but difficult for computers to process.
- Structured Data: Information organized in a predictable format. A spreadsheet with clear columns (like 'Name', 'Email', 'Company') or a JSON object with key-value pairs are perfect examples. It's easy for computers to search, sort, and analyze.
The goal is to use an LLM to bridge the gap between these two formats automatically.
Data Extraction for Chatbot Users
You can perform powerful data extraction using a standard chatbot interface. The key is to be extremely specific in your prompt about both what you want to extract and how you want it formatted.
Your prompt should include three key parts:
- The Context: Clearly state the goal. For example, 'I am extracting contact information from this email signature.'
- The Input Data: Provide the block of text you want to parse. It's often helpful to wrap it in triple quotes (`"""`) to separate it from your instructions.
- The Output Format: This is the most important part. Tell the model exactly what the final output should look like. You can ask for a markdown table, a comma-separated list, or even describe a JSON object.
Here's an example prompt:
Extract the name, job title, and phone number from the following text. Format the output as a markdown table with three columns: 'Full Name', 'Title', and 'Phone'.
"""From: Jane DoeSubject: Project Update...Best,Jane Doe, Senior Product ManagerACME Corp | 555-123-4567"""
The LLM will then produce a clean, structured table that you can easily copy and paste.
Reliable Extraction for Developers (JSON Mode)
When building an application, you need the output to be perfectly structured every time so your code can process it. A markdown table is great for humans, but machine-readable formats like JSON are better for software.
Many modern LLM APIs offer a feature called JSON mode. When enabled, it constrains the model to only output a valid JSON object that conforms to a schema you can define. This is far more reliable than simply asking for JSON in the prompt.
Here's a conceptual example of how you might use this in an API call:
response = client.chat.completions.create(
model="gpt-4o",
response_format={ "type": "json_object" },
messages=[
{"role": "system", "content": "You are a data extraction expert. Extract user details into a JSON object."},
{"role": "user", "content": "Extract the user info from this text: 'John Smith is a software engineer from New York.' You must include fields for name, job, and city."}
]
)This call forces the model to respond with a clean JSON object like:
{ "name": "John Smith", "job": "software engineer", "city": "New York" }
This output can be directly parsed and used by your application without any extra cleanup, making it a robust solution for automated workflows.
FAQ on LLM Data Extraction
How accurate is it?
Accuracy is generally high for clear, well-formatted text. It can struggle with ambiguous, complex, or poorly written source material. For critical applications, it's wise to include a human review step to validate the extracted data.
What if some information is missing in the text?
You can instruct the model on how to handle missing data. For example, in your prompt, you can add, 'If a piece of information is not found, use a value of null or an empty string for that field.'
Can it extract data from tables or images?
LLMs are best at parsing text. For data in images, you would first need to use an Optical Character Recognition (OCR) tool to convert the image to text, which you can then feed to the LLM. Some multimodal models can handle images directly, but this is a more advanced use case.
Key Takeaways
- LLMs are excellent tools for converting unstructured text into structured data like tables, CSV, or JSON.
- For no-code users, a successful prompt clearly defines the input text and the desired output format.
- For developers, using API features like JSON mode provides reliable, machine-readable output for automated workflows.
- Be explicit about how the model should handle missing or ambiguous information.
- Always consider a human validation step for workflows where data accuracy is critical.
Related Reading
- How to Force an LLM to Generate Perfect JSON Every Time
- The Prompt Chaining Workflow: How to Tackle Complex Tasks with AI
- A Beginner's Guide to Data Analysis with an LLM