Turns unstructured text into an interactive knowledge graph by using an LLM to extract subject-predicate-object triples.
google/langextract
A Python library that uses LLMs to pull structured data from unstructured text, with each extraction linked back to its source span.
- Stars
- 39,274
- Forks
- 2,750
- Open issues
- 114
- Last commit
- yesterday
What is it?
LangExtract takes a plain-language extraction prompt and a few example annotations, then runs an LLM over a document to return entities and attributes in a consistent schema. Each extracted value is mapped to its exact character interval in the source, so results can be checked against the original text. Extractions that cannot be located in the input are marked with no interval, which makes it easy to filter out model hallucinations drawn from the examples.
For long documents, the library splits text into chunks, processes them in parallel, and supports multiple extraction passes to improve recall. Results can be saved as JSONL and rendered as a self-contained interactive HTML file for reviewing entities in context. Gemini models are the primary target, with built-in support for OpenAI and local models through Ollama, and a plugin system for adding other providers.
Key features
- 01Maps each extracted entity to its exact location in the source text.
- 02Enforces a consistent output schema defined by few-shot examples.
- 03Splits long documents into chunks with parallel processing and multiple passes.
- 04Generates an interactive, self-contained HTML visualization of results.
- 05Supports Gemini, OpenAI, and local models via Ollama.
- 06Offers a plugin system for adding custom model providers.
Use cases
- Structuring clinical notes or radiology reports into searchable fields.
- Pulling characters, relationships, or events out of novels and long texts.
- Turning contracts or documents into verifiable structured records.
- Prototyping an information extraction pipeline without fine-tuning a model.
Quick start
- 1
Install the package from PyPI
pip install langextract - 2
Set your API key for cloud models such as Gemini
export LANGEXTRACT_API_KEY="your-api-key-here" - 3
Write a prompt and examples, then call lx.extract with your input text
Things to know
- Cloud models like Gemini and OpenAI require a paid or API key account.
- Extraction quality depends on the chosen LLM, prompt wording, and examples.
In collections
Topics
FAQ
- What is langextract?
- A Python library that uses LLMs to pull structured data from unstructured text, with each extraction linked back to its source span. LangExtract takes a plain-language extraction prompt and a few example annotations, then runs an LLM over a document to return entities and attributes in a consistent schema. Each extracted value is mapped to its exact character interval in the source, so results can be checked against the original text. Extractions that cannot be located in the input are marked with no interval, which makes it easy to filter out model hallucinations drawn from the examples.
- Is langextract free to use? What license does it have?
- langextract is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
- Is langextract still maintained?
- Actively maintained. The last commit to langextract was on Nov 6, 2026.
- What can I use langextract for?
- Structuring clinical notes or radiology reports into searchable fields. Pulling characters, relationships, or events out of novels and long texts. Turning contracts or documents into verifiable structured records. Prototyping an information extraction pipeline without fine-tuning a model.
- How do I install langextract?
- Install the package from PyPI: pip install langextract Set your API key for cloud models such as Gemini: export LANGEXTRACT_API_KEY="your-api-key-here" Write a prompt and examples, then call lx.extract with your input text
- Where can I get langextract?
- The source code and installation instructions are on GitHub: https://github.com/google/langextract
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
An open-source AI agent from Google that brings Gemini into your terminal to query, edit, and automate code.
A collection of agent skills that give AI coding assistants up-to-date context for building apps with the Gemini API and SDKs.
A community-maintained PHP client for the Gemini API, covering text, media, streaming, tools, and file and cache management.
An LLM-powered web scraper, built on Streamlit, that extracts data from pages using OpenAI, Gemini, Ollama or LiteLLM models.
A GitHub Action that posts AI-generated code review comments on pull requests, triggered by a /gemini-review comment, using Google's Gemini API.