What this thread does
Do first: create a virtual environment with python -m venv langextract_env, activate it, then run pip install langextract and set LANGEXTRACT_API_KEY (or point it at a local Ollama model) before the first lx.extract call. README
Short answer
LangExtract is a Python library that uses an LLM to extract structured fields from unstructured text according to your instructions and a few examples; grounded results have source character intervals, while extractions that cannot be located have char_interval = None. README It handles long documents by chunking, parallel workers and several passes, and writes an interactive HTML view for reviewing results in context. README The README says it is not an officially supported Google product and is licensed under Apache 2.0. README
Choose / don't choose
| Backend | Choose it when | Not for |
|---|---|---|
| Gemini through an API key | You want the README's recommended default, gemini-3.5-flash, with schema-constrained output | Free-tier throughput on large jobs: the README suggests a paid tier for large-scale or production use |
OpenAI (pip install langextract[openai]) | Your team already has an OpenAI key; large non-urgent jobs can opt into the Batch API | Needs for fence_output or use_schema_constraints tuning: the README says to leave both unset |
Ollama local model (for example gemma2:2b at http://localhost:11434) | No API key and data must stay local | Custom output_schema: the README says Ollama does not currently support it |
Settings that matter
| Setting | Behavior | Source |
|---|---|---|
LANGEXTRACT_API_KEY | API key for cloud models, from AI Studio, Vertex AI or the OpenAI Platform; a .env file is the README's recommended option, with .env added to .gitignore | README |
examples | Few-shot ExampleData; each extraction_text should be verbatim from the example text, in order; otherwise Prompt alignment warnings appear | README |
extraction_passes, max_workers, max_char_buffer | Multiple passes for recall, parallel workers, smaller chunks for accuracy; the README example uses 3, 20 and 1000 | README |
model_id | Selects the provider automatically (Gemini, OpenAI, Ollama); a ModelConfig with an explicit provider is for OpenAI-compatible endpoints | README |
| Python | The package requires Python 3.10 or newer | PyPI |
Order of operations
1. python -m venv langextract_env, activate it, then pip install langextract. README 2. Put LANGEXTRACT_API_KEY=... in a .env file and add .env to .gitignore; skip the key if you use Ollama. README 3. Write a prompt that says what to extract and add one high-quality example whose extraction_text is verbatim from its text. README 4. Call lx.extract(text_or_documents=..., prompt_description=..., examples=..., model_id="gemini-3.5-flash"). README 5. Keep only grounded results: extractions the library cannot locate in the source have char_interval = None, so filter with [e for e in result.extractions if e.char_interval]. README 6. Save results to JSONL with lx.io.save_annotated_documents and render the HTML review with lx.visualize. README
Known failures and fixes
- The model returns content from your example instead of the input: the README says this can happen and that ungrounded extractions have
char_interval = None; filter them. README Prompt alignmentwarnings: fix examples so extraction text is verbatim and in order of appearance. README- Model ID stops working: the README notes Gemini models have retirement dates and points to the official model-version documentation; its named default may change. README
- Rate limits on big runs: use a paid Gemini tier or a batch option, as the README suggests. README
- Medical text: the README says its medication demo is not for medical advice and that health applications are also subject to Health AI Developer Foundations Terms of Use. README
Missing
- No accuracy figures are cited here; extraction quality depends on the model, task and examples, as the README says.
- Price per document is not stated and depends on the provider.
Evidence
google/langextract README at commit e086340 (2026-12-01) and the PyPI project page (version 1.7.2 uploaded 2026-11-07), read 2026-12-03. 0 trials in this draft; not tried by WhatWorks.
Checked
2026-12-03; README and PyPI metadata were read as served on that date.
Started from a post by @Google (google/langextract), packaged by the editor. Original post