Find your next open-source project

Search by name, purpose, or keyword, or paste a GitHub URL. Start with / to search agent skills (e.g. /pdf)

google/langextract

AI EngineeringKnowledge bases

Extracts schema-structured entities from long text with LLM calls and maps each result to its exact source span.

This project ships 1 agent skillsSkill list and install →
39,478
2,779
Python
Apache-2.0
1 year old

What it does

LangExtract wraps an LLM in a few-shot extraction pipeline. You supply a natural-language instruction, a small example containing ExampleData and Extraction objects, and the input text; the library chunks long documents, runs extraction in parallel (optionally over multiple passes), and returns entities whose char_interval points back to the characters in the original source. That grounding is what distinguishes it from plain JSON-mode prompting: any extraction the model pulls from the examples rather than the input gets char_interval = None and can be filtered out.

It is aimed at teams that need auditable structured data from reports, clinical notes, novels, and similar long, unstructured text without fine-tuning a model. Supported backends include the Gemini family through AI Studio or Vertex AI, OpenAI models, Ollama for local inference, and third-party providers registered through a plugin router.

Quick start

Install from PyPI, then set an API key for a hosted model:

pip install langextract
export LANGEXTRACT_API_KEY="your-api-key"

Define a prompt and one high-quality example whose extraction_text values appear verbatim in the example text, then call lx.extract with the input and a model_id. The README's Romeo and Juliet snippet is a complete minimal program: it extracts characters, emotions, and relationships from a single sentence using gemini-3.5-flash. Save the result with lx.io.save_annotated_documents([result], output_name="extraction_results.jsonl", output_dir=".") and render lx.visualize("extraction_results.jsonl") to an HTML file to review highlighted entities in context.

For a no-install check, there is a hosted demo of grounded extraction over Romeo and Juliet.

Long documents and scale

lx.extract accepts a URL with fetch_urls=True, and extraction_passes, max_workers, and max_char_buffer control recall and parallelism for book-length inputs. Cost-sensitive batch jobs can use Vertex AI's Batch API or OpenAI's Batch API via language_model_params, with an opt-in threshold for when to switch to batch mode.

Constraints

Hosted Gemini and OpenAI models need credentials: an API key in LANGEXTRACT_API_KEY or OPENAI_API_KEY, or Vertex AI service-account parameters. Local Ollama models avoid keys but do not support output_schema. Schema-constrained output is strongest on Gemini and OpenAI; other backends may rely on JSON mode. Extraction quality depends on the model, prompt wording, and example quality, so the project warns about prompt-alignment issues and occasionally ungrounded extractions. The license is Apache-2.0, and the README states this is not an officially supported Google product; health-related use also carries the Health AI Developer Foundations terms. The medical examples are demonstrations, not clinical advice.

HotRepo's take

The project appeared on Hacker News in July 2025 with 166 points and 14 comments. Discussion compared it with document ETL tools such as Unstract and with Simon Willison's earlier schema-based extraction work, while one commenter noted the title's imprecision: the model extracts structured data from input rather than from the model itself. That matches the library's actual scope. The substantial star count is not backed by any recorded daily-ranking position in the HotRepo data, so no trend claim is warranted here.

Project source and documentation

Written by AI from the project's public information and HotRepo's records, updated . The project's own docs are the source of truth.

Hacker News

LangExtract: Python library for extracting structured data from language models
▲ 166 · 14 comments · July 30, 2025

You might also like

  1. neuml/txtaiAn all-in-one Python framework for semantic search, RAG pipelines, LLM workflows and agents built on an embeddings database.Python13,126
  2. Graphify-Labs/graphifyBuilds a local, queryable knowledge graph of a codebase so coding agents can navigate it instead of grepping.Python134,240
  3. colbymchenry/codegraphBuilds a local code knowledge graph that gives coding agents exact symbols, call paths and change impact in one query.TypeScript77,931
  4. google-gemini/cookbookOfficial Gemini API tutorials and runnable notebooks for developers learning prompting, multimodal input, agents, media generation and grounding.Jupyter Notebook18,143
  5. google-gemini/gemini-api-cliA Go CLI that lets coding agents and shell scripts call Gemini models, generate media, analyze files, and run managed agents.Go462