google/langextract
A Python library for extracting structured information from unstructured text using LLMs with precise source grounding and interactive visualization.
What it solves
LangExtract is designed to extract structured information from unstructured text documents (such as clinical notes or reports) using Large Language Models (LLMs). It specifically addresses the challenge of "needle-in-a-haystack" extraction in long documents and the need for precise source grounding, ensuring that every piece of extracted data can be traced back to its exact location in the original text.
How it works
The library uses a combination of user-defined prompts and few-shot examples to guide an LLM to identify and organize key details. To handle large documents, it employs a strategy of text chunking, parallel processing, and multiple extraction passes to increase recall. It supports a wide range of models, including cloud-based options like Google Gemini and OpenAI, as well as local models via Ollama. The system automatically detects if an extraction is grounded in the source text or if the LLM has hallucinated information from the examples, marking the latter with a null character interval.
Who it’s for
It is intended for developers and researchers who need to convert unstructured text into structured data without fine-tuning a model, particularly those working with long documents or in domains like healthcare where traceability and verification are critical.
Highlights
- Precise Source Grounding: Maps every extraction to its exact character span in the source text for easy verification.
- Reliable Structured Outputs: Uses controlled generation and few-shot examples to enforce consistent output schemas.
- Long Document Optimization: Uses parallel processing and chunking to maintain high recall across large texts.
- Interactive Visualization: Generates self-contained HTML files to visually review extracted entities in their original context.
- Flexible Model Support: Compatible with Gemini, OpenAI, and local LLMs via Ollama, with a plugin system for custom providers.
Related
- Project
- Project
- Project
- Project
- Project