Extract structured information from unstructured text with pattern-matching precision.
A Python package that simplifies structured data extraction from plain text inputs using a language model with pattern-matching capabilities. Ideal for surveys, feedback analysis, and report generation where consistent, well-formatted outputs are required.
- Pattern-based extraction: Uses regex patterns to enforce structured output formats.
- Flexible LLM integration: Works with default
ChatLLM7or any LangChain-compatible model. - No multimedia support: Focuses solely on text-based inputs for reliability.
- Consistent formatting: Ensures responses match expected schemas (tables, summaries, key-value pairs).
- Easy customization: Replace default LLM with OpenAI, Anthropic, Google, or any other LangChain model.
pip install structuredxtractfromstructuredxtractimportstructuredxtractuser_input="""Name: John DoeAge: 30Occupation: Software Engineer"""response=structuredxtract(user_input)
print(response) # Structured output based on predefined patternsReplace the default ChatLLM7 with your preferred model:
fromlangchain_openaiimportChatOpenAIfromstructuredxtractimportstructuredxtractllm=ChatOpenAI()
response=structuredxtract(user_input, llm=llm)fromlangchain_anthropicimportChatAnthropicfromstructuredxtractimportstructuredxtractllm=ChatAnthropic()
response=structuredxtract(user_input, llm=llm)fromlangchain_google_genaiimportChatGoogleGenerativeAIfromstructuredxtractimportstructuredxtractllm=ChatGoogleGenerativeAI()
response=structuredxtract(user_input, llm=llm)- Default: Uses
LLM7_API_KEYfrom environment variables. - Manual override: Pass via
api_keyparameter or setLLM7_API_KEYbefore importing.importosos.environ["LLM7_API_KEY"] ="your_api_key_here"
Get a free API key at LLM7 Token.
| Parameter | Type | Description |
|---|---|---|
user_input | str | Plain text input to extract structured data from. |
api_key | Optional[str] | LLM7 API key (optional if using environment variable). |
llm | Optional[BaseChatModel] | Custom LangChain LLM (e.g., ChatOpenAI, ChatAnthropic). Defaults to ChatLLM7. |
Returns a List[str] of extracted data matching predefined patterns. Example:
[
{"Name": "John Doe", "Age": "30", "Occupation": "Software Engineer"},
{"Key1": "Value1", "Key2": "Value2"}
]- LLM7 Free Tier: Sufficient for most use cases.
- Custom API Key: For higher limits, pass via
api_keyor environment variable.
MIT
For bugs or feature requests, open an issue on GitHub.
Eugene Evstafev 📧 hi@euegne.plus 🔗 GitHub: chigwell