--- id: langextract version: "1.6.0" license: Apache-2.0 license_treatment: permissive maintenance: active --- # langextract — LangExtract: A library for extracting structured data from language models License: permissive · Maintenance: active · Downloads: 407.1K/mo ## 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 above — 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 pip install langextract uv add langextract 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_current - Install friction: low - Maintenance: active - Downloads: 407.1K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags llm structured information extraction, text entity extraction with source grounding, document parsing with language models, extract data from unstructured text, llm-powered data annotation, schema-constrained text extraction, interactive extraction visualization, llm-extraction, document-parsing, data-annotation [View on SkillFed](https://skillfed.io/packages/langextract) · [View on PyPI](https://pypi.org/project/langextract/)