skillfed

langextract

LangExtract: A library for extracting structured data from language models

langextract v1.6.0 407.1K downloads/30d#6,890 on PyPI38,376
Permissive license Apache-2.0 Active released

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 langextract

uv

uv add langextract

poetry

poetry add langextract

Installing 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

llm structured information extractiontext entity extraction with source groundingdocument parsing with language modelsextract data from unstructured textllm-powered data annotationschema-constrained text extractioninteractive extraction visualization
llm-extractiondocument-parsingdata-annotation

More Artificial Intelligence packages