graph LR
Input_Document_Handler["Input/Document Handler"]
Prompt_Management_Module["Prompt Management Module"]
LLM_Abstraction_Layer["LLM Abstraction Layer"]
Extraction_Engine["Extraction Engine"]
Data_Structuring_Validation_Module["Data Structuring/Validation Module"]
Output_Serialization_Module["Output/Serialization Module"]
Input_Document_Handler -- "provides pre-processed document content to" --> Prompt_Management_Module
Prompt_Management_Module -- "sends prepared prompts for LLM inference to" --> Extraction_Engine
Extraction_Engine -- "requests LLM inference and obtains LLM instances from" --> LLM_Abstraction_Layer
Extraction_Engine -- "passes raw LLM responses for post-processing to" --> Data_Structuring_Validation_Module
Data_Structuring_Validation_Module -- "provides structured and validated data to" --> Output_Serialization_Module
The langextract subsystem is designed for efficient information extraction using Large Language Models. The process begins with the Input/Document Handler, which is responsible for ingesting various document formats and preparing them for processing. The prepared content is then passed to the Prompt Management Module, which dynamically constructs and formats prompts tailored for the LLM, incorporating document content and extraction requirements. These prompts are then sent to the Extraction Engine, the core orchestrator of LLM interactions. The Extraction Engine communicates with different LLM providers through the LLM Abstraction Layer, ensuring a unified interface regardless of the underlying LLM. After receiving raw responses from the LLM, the Extraction Engine forwards them to the Data Structuring/Validation Module. This module transforms the unstructured LLM output into a predefined structured format and validates it against expected schemas. Finally, the Output/Serialization Module handles the serialization of the validated, structured data into various output formats and manages its persistence or delivery. This modular design ensures clear separation of concerns, flexibility in LLM integration, and robust data handling throughout the extraction pipeline.
Responsible for ingesting raw documents (e.g., JSONL, HTML) and preparing them for the extraction process, potentially converting them into a standardized internal representation suitable for prompt generation.
Related Classes/Methods:
langextract.io.Dataset:39-79langextract.io.load_annotated_documents_jsonl:137-185langextract.io.download_text_from_url:232-318
Manages the creation, templating, and preparation of specific prompts tailored for the LLM based on the input document content and the desired information extraction task.
Related Classes/Methods:
langextract.prompting.PromptTemplateStructured:38-48langextract.prompting.QAPromptGenerator:83-166
Provides a unified, abstract interface for interacting with various LLM providers (e.g., Google Gemini, OpenAI, Ollama). It handles the registration, management, and instantiation of different LLM backends, abstracting away their specific API differences. This enables LLM-agnostic core logic.
Related Classes/Methods:
langextract.providers.registrylangextract.providers.geminilangextract.providers.openailangextract.providers.ollamalangextract.factory
Orchestrates the core interaction with LLMs for information extraction. It is responsible for sending prepared prompts to the LLM via the LLM Abstraction Layer, managing the responses, and handling the overall extraction logic, including any retry mechanisms or error handling related to LLM communication.
Related Classes/Methods:
langextract.inference
Responsible for taking the raw, unstructured output from the LLM and transforming it into a predefined structured format (e.g., JSON). It also performs validation to ensure the extracted data conforms to expected schemas and quality standards.
Related Classes/Methods:
langextract.schema.BaseSchema:49-59langextract.schema.GeminiSchema:62-158
Handles the final serialization of the structured and validated extracted data into various output formats (e.g., JSONL, CSV) and manages its persistence or delivery.
Related Classes/Methods:
langextract.io.save_annotated_documents:82-134