langextract
LangExtract: A library for extracting structured data from language models
What it is and what it does
LangExtract is a Python library that uses large language models to extract structured information from unstructured text—such as clinical notes, reports, or literary documents—based on user-defined extraction rules and few-shot examples. It maps every extracted entity back to its exact location in the source text, enabling visual verification and traceability. The library handles long documents through optimized chunking and parallel processing, supports multiple LLM providers (Google Gemini, OpenAI, local Ollama), and generates interactive HTML visualizations to review thousands of extracted entities in their original context.
The core workflow involves defining a prompt that describes what to extract, providing high-quality examples to guide the model, running the extraction on your input text, and optionally visualizing results. LangExtract enforces consistent output schemas and detects when the model extracts content from examples rather than the source text. It is designed for domains where precise source grounding and schema-constrained outputs matter—medical records, legal documents, research papers, or any scenario where traceability and structured output are critical.
Use it for:
- Extract medications, diagnoses, and clinical findings from medical notes with exact source citations for audit and verification.
- Parse radiology or pathology reports to structure unstructured narrative text into standardized data fields.
- Identify characters, relationships, and emotions from literary texts with interactive visualization for literary analysis.
- Annotate and label large document collections for machine learning training datasets with built-in grounding and conflict detection.
- Extract key entities and attributes from legal contracts or regulatory documents while maintaining source traceability.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
LangExtract uses LLMs to extract and ground structured information from unstructured text, mapping each extraction to its exact source location and generating interactive visualizations of results.
Yes. LangExtract is actively maintained, has low install friction, carries no known vulnerabilities, and offers a permissive Apache-2.0 license. It solves a concrete problem—grounded structured extraction from unstructured text—with built-in visualization and multi-provider LLM support. Install it if you need to extract and ground structured data from documents with traceability and schema enforcement. Requires Python 3.10+ and an LLM provider (cloud or local).
Install
langextract on PyPI
pip
pip install langextractuv
uv add langextractpoetry
poetry add langextractInstalling langextract
Before you install
Low install friction with a pure-wheel distribution. Active maintenance with recent commits and high repository engagement (38376 stars). Requires Python 3.10+. Depends on 17 runtime packages including google-genai, google-cloud-storage, and standard data-processing libraries.
License in practice
Apache-2.0 permissive license allows commercial and private use with minimal restrictions, making it suitable for most production and research applications.
Quickstart
import langextract as lx
prompt = "Extract characters and emotions in order of appearance."
examples = [lx.data.ExampleData(
text="ROMEO. But soft! What light through yonder window breaks?",
extractions=[lx.data.Extraction(
extraction_class="character",
extraction_text="ROMEO",
attributes={"emotional_state": "wonder"}
)]
)]
result = lx.extract(
text_or_documents="Your input text here",
prompt_description=prompt,
examples=examples,
model_id="gemini-3.5-flash"
)
Requires Python 3.10+. Cloud model usage (e.g., Gemini) requires an API key; local models via Ollama are also supported.
Verify before relying
- Whether the package handles rate limiting gracefully for high-volume extraction workloads.
- Performance characteristics and throughput for documents exceeding typical LLM context windows.
- Exact behavior when extractions cannot be grounded in source text beyond the documented char_interval = None filtering.
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 17 — absl-py, aiohttp, async_timeout, exceptiongroup, google-genai, google-cloud-storage, ml-collections, more-itertools, numpy, pandas, pydantic, python-dotenv, PyYAML, regex, requests, tqdm, typing-extensions |
| Maintenance | actively maintained — 43 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 407,057/month — #6,890 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: langextract-1.6.0-py3-none-any.whl
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
instructorInstructor wraps LLM APIs to extract validated,…
permissive · top 5,000 on PyPI
graphragGraphRAG extracts structured knowledge graphs…
permissive · top 15,000 on PyPI
llmLLM is a CLI tool and Python library for…
permissive · top 15,000 on PyPI
gliner2GLiNER2 extracts entities, classifies text,…
permissive · top 15,000 on PyPI
glinerGLiNER is a lightweight framework for named…
permissive · top 15,000 on PyPI
trustcallTrustcall helps LLMs reliably generate and…
permissive · top 5,000 on PyPI
llama-indexLlamaIndex is a data framework that connects…
permissive · top 5,000 on PyPI
llm-guardLLM Guard provides input and output scanning…
unclear · top 15,000 on PyPI
gitingestConverts Git repositories into plain-text…
permissive · top 15,000 on PyPI
doclangDocLang is a reference toolkit for validating…
permissive · top 5,000 on PyPI