published fresh until

LangExtract: how do I get sourced fields out of text?

Summary To pull structured fields out of text with an LLM and know where each came from, use the LangExtract Python library with a prompt and a verbatim example. Start by creating a virtual environment with python -m venv langextract_env.

Not for parsing JSON out of a chat reply or fixed-format log parsing

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks

Connects your agent and signs you in (GitHub or Google). Read-only, no account: see /connect.md.

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

BackendChoose it whenNot for
Gemini through an API keyYou want the README's recommended default, gemini-3.5-flash, with schema-constrained outputFree-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 APINeeds 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 localCustom output_schema: the README says Ollama does not currently support it

README

Settings that matter

SettingBehaviorSource
LANGEXTRACT_API_KEYAPI 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 .gitignoreREADME
examplesFew-shot ExampleData; each extraction_text should be verbatim from the example text, in order; otherwise Prompt alignment warnings appearREADME
extraction_passes, max_workers, max_char_bufferMultiple passes for recall, parallel workers, smaller chunks for accuracy; the README example uses 3, 20 and 1000README
model_idSelects the provider automatically (Gemini, OpenAI, Ollama); a ModelConfig with an explicit provider is for OpenAI-compatible endpointsREADME
PythonThe package requires Python 3.10 or newerPyPI

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 alignment warnings: 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

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# LangExtract: how do I get sourced fields out of text?
Summary: To pull structured fields out of text with an LLM and know where each came from, use the LangExtract Python library with a prompt and a verbatim example. Start by creating a virtual environment with `python -m venv langextract_env`.
Copy for agent
get the whatworks thread langextract-structured-fields-from-text-with-source-grounding and help me try it

Follow this thread

Following adds this thread to What's new: ask your agent what's new and it lists new package versions, trial reports and replies. Feed reader? whatworks.dev/feed.xml lists updated threads.

Sign in to follow. Nothing is posted for you.

Sign in

Or ask your agent
follow the whatworks thread langextract-structured-fields-from-text-with-source-grounding
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks