Google LangExtract is an open-source Python library that transforms unstructured text documents into verified structured JSON data while mapping every single extracted point to its exact character location in the original text.
| Step 1: Input Document | Step 2: AI Grounding Action | Step 3: Verifiable Result |
|---|---|---|
| Load chaotic text or financial PDF file | Schema enforcement & multi-pass character offset mapping | Structured JSON with 100% verifiable source character spans |
Before running the pipeline, create your input document in the root directory:
- Create File: Create a text file named
NVIDIA_Q4_FY25_Financial_Report.txtin the root folder. - Add Content: Copy and paste any corporate press release, SEC filing, earnings report, or clinical note text into
NVIDIA_Q4_FY25_Financial_Report.txt. - (Alternatively, configure
INPUT_DOCUMENTinmain.pyto point to any custom text file).
Run these copy-pasteable commands in your Windows PowerShell terminal:
# 1. Create and activate a Python virtual environment
python -m venv venv
.\venv\Scripts\Activate.ps1
# 2. Install Google LangExtract and LLM provider SDKs
pip install langextract google-genai openai
# 3. Pull the local Ollama model (Optional for local execution)
ollama pull qwen3:4b
# 4. Execute the financial extraction pipeline
python main.pyLangExtract supports Ollama (local), Google Gemini, and OpenAI. Configure your preferred provider in main.py:
- Ensure Ollama is running locally (
ollama serve). - In
main.py, setMODEL_PROVIDER = "ollama"and specify your model (e.g.OLLAMA_MODEL = "qwen3:4b").
- Go to Google AI Studio.
- Click Create API Key and copy your key string.
- Set your environment variable in PowerShell:
$env:GEMINI_API_KEY="your_gemini_api_key_here"
- In
main.py, setMODEL_PROVIDER = "gemini"andOLLAMA_MODEL = "gemini-2.5-flash".
LangExtract/
├── main.py # Core extraction script & schema provider
├── .env # API keys & environment configuration
└── README.md # Project documentation and setup guide
main.py: Reads the target financial document, initializes the schema-enforcedExtractor, executes character offset grounding, measures latency per query, and exports the final verified findings..env: Stores local system parameters and cloud provider credentials securely.
- 🏥 Clinical Note & EHR Extraction: Parse physician notes to extract patient diagnoses, dosages, and treatment plans with source character audit trails for medical compliance.
- 📊 Financial PDF & Earnings Audit: Extract revenue, gross margins, cash balances, and risk disclosures from corporate filings with 100% verifiable quotes.
- ⚖️ Legal Contract Clause Analysis: Extract termination conditions, liability caps, and indemnification clauses paired with exact line/character offsets.
- 📑 Insurance Claims Processing: Convert chaotic accident reports and policy forms into structured JSON claims data for automatic adjudication.
- 🎙️ Podcast & Customer Call Analytics: Pull key customer feature requests, sentiment signals, and competitor mentions directly from raw audio transcripts.
- 🌐 Multi-Modal Document Parsing: Native OCR ingestion for scanned PDFs, tables, and handwritten medical records.
- 🔄 Automated RAG Knowledge Graph: Feed character-grounded extractions into vector databases for hallucination-free enterprise search.
- 📱 Real-Time Stream Grounding: Live character index mapping for streaming voice calls and customer support chats.
- 🛡️ Confidence Score Calibration: Automatic flagging of ambiguous text spans requiring human-in-the-loop review.
- 🚀 Distributed Multi-GPU Processing: Accelerated parallel chunking for enterprise documents exceeding 100,000 pages.
Google LangExtract, Local Document AI, Ollama Structured Extraction, Zero Hallucination LLM, Python Source Grounding, Gemini API, OpenAI JSON Schema, Enterprise Document Parsing