LangExtract is a Python library that pulls structured entities from unstructured text using LLMs, with chunking for long documents and HTML review output.
Overview
LangExtract lets you define extraction tasks in natural language with few-shot examples, then run them against clinical notes, reports, literature, or other unstructured text. The library returns structured records aligned to character intervals in the source so you can verify each span.
For long inputs it chunks text, processes chunks in parallel, and can run multiple passes to improve recall on needle-in-a-haystack content. Results can be written to JSONL and rendered as a self-contained interactive HTML visualization that highlights entities in context.
Model support includes Google Gemini through API keys or Vertex AI service accounts, OpenAI models via an optional extra, local models through Ollama, and custom providers registered as plugins. Schema-constrained outputs are available on supported cloud models.
Optional batch modes integrate with Vertex AI or OpenAI batch APIs for cost-sensitive large jobs. Domain adaptation relies on prompt wording and examples rather than fine-tuning, and extractions without a matching source span can be filtered when strict grounding is required.
Key features
- Few-shot prompt-defined extractions
- Character-level source grounding
- Long-document chunking and parallel runs
- Interactive HTML visualization export
- Gemini, OpenAI, and Ollama backends
- Custom LLM provider plugins
- Vertex AI and OpenAI batch modes
- JSONL output for downstream pipelines
Use cases
- Structuring clinical or medical notes
- Literary or legal entity extraction
- Radiology report field parsing
- Research pipelines needing cited spans