langextract-usage
Skill39k starsChanged 8 months agoApache-2.0View on GitHub
How to use LangExtract to extract structured information from text. Use when writing code that calls lx.extract(), building extraction pipelines, defining examples, or troubleshooting alignment issues.
- Reads credentials
- Installs packages
Trending
More talk lately.about the whole repository
Who's talking about google/langextract
- A Hacker News story“LangExtract: Python library for extracting structured data from language models”Hacker News · Jul 30, 2025 · 166 points
- @sungkim.bsky.social“Google LangExtract: A Gemini powered information extraction library Process large volumes of unstructured …”Bluesky · Jul 31, 2025 · 23 likes
- @stephenturner.us“langextract: A Python library for extracting structured information from unstructured text using LLMs with …”Bluesky · Feb 10, 2026 · 6 likes
- @github-trending.bsky.social“🚀 Skyrocketing! 🚀 (200+ new stars) 📦 google / langextract ⭐ 20,953 (+329) 🗒 Python A Python library for …”Bluesky · Jan 16, 2026 · 5 likes
- @bearstech.com“LangExtract : une lib Open Source écrite en Python par Google permettant d'extraire automatiquement des …”Bluesky · Dec 23, 2025 · 5 likes
The biggest 5 of 75 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 75
Talked about on GitHub, Bluesky and Hacker News (75 times).
On GitHub · 50
- Feb 11, 2026[Feature Request]: Integrate Google LangExtract for LLM-Powered Semantic Extraction in Ingestion Pipeline — infiniflow/ragflow2 reactions · 7 comments
- Apr 12, 2026Add LangExtract plugin — agent0ai/a0-plugins1 reaction
- Jan 21, 2026```suggestion — LumoSQL/archive1-LumoSQL-on-github1 reaction · 3 comments
- Aug 3, 2025Add link to readme — jooooel/TIL1 reaction
- Oct 29, 2026X bookmark: evaluate Google's LangExtract for document extraction (Fundarem / AI-for-companies) — winnr-dotcom/claude-inbox0 reactions · 1 comment
45 more on GitHub
- Oct 26, 2026Update dependency langextract to v1.7.2 — blck-snwmn/hello-langextract0 reactions
- Oct 26, 2026Update dependency langextract to v1.7.1 — blck-snwmn/hello-langextract0 reactions
- Oct 26, 2026Update dependency langextract to v1.0.9 — blck-snwmn/hello-langextract0 reactions
- Oct 20, 2026build(deps): update langextract requirement from >=0.1.0 to >=1.7.1 — POWERFULMOVES/PMOVES-DoX0 reactions · 1 comment
- Oct 18, 2026Proposal: 可审计行业搜索与证据采集——固定代码、Skill 与小/大模型级联 — zehaoli0324-cloud/groundsignal0 reactions
- Oct 9, 2026whisker: deterministic QA for tomd conversions — cppalliance/wg21-paperflow0 reactions
- Sep 23, 2026Build(deps): Bump langextract from 1.6.0 to 1.7.0 in /worker — blakeox/extractflow0 reactions · 3 comments
- Sep 23, 2026Bump langextract from 1.6.0 to 1.7.0 — blakeox/extractflow0 reactions · 3 comments
- Sep 16, 2026Bump langextract from 1.5.0 to 1.6.0 in /worker — blakeox/extractflow0 reactions · 1 comment
- Aug 16, 2026§16.5's metric rule could be a deterministic substring check if §15.2 returned source offsets — jointsome0-lgtm/exp2res0 reactions
- Aug 4, 2026build(deps): update langextract requirement from >=0.1.0 to >=1.6.0 — POWERFULMOVES/PMOVES-DoX0 reactions · 1 comment
- Jul 27, 2026Update langextract requirement from >=1.0.0 to >=1.6.0 in /presidio-analyzer — rkwap/presidio0 reactions · 1 comment
- Jul 22, 2026pdf ocr etc — gatrivi/catts0 reactions
- Jul 19, 2026Pilot source-grounded ontology candidate extraction on sanitized Femme and JMD sources — sabnanikl-dev/client-ontologies0 reactions
- Jul 19, 2026Add an isolated LangExtract toolchain for source-grounded ontology intake — sabnanikl-dev/client-ontologies0 reactions
- Jul 1, 2026UND-28 LangExtract fact extraction из chunks — StearD2k/underdog-team0 reactions · 1 comment
- May 27, 2026Bump langextract from 1.3.0 to 1.5.0 in /worker — blakeox/extractflow0 reactions
- May 4, 2026deps(api): bump the python-deps group across 1 directory with 8 updates — JonathanRReed/JR-AutoRAG0 reactions · 1 comment
- Apr 27, 2026deps(api): bump the python-deps group in /api with 7 updates — JonathanRReed/JR-AutoRAG0 reactions · 1 comment
- Apr 19, 2026feat(openai): add Batch API support (#309) — baobaodawang-creater/langextract0 reactions
- Apr 17, 2026build(deps-dev): update langextract requirement from >=1.0.0 to >=1.2.1 in /presidio-analyzer — 1sh1ro/presidio-plus0 reactions · 1 comment
- Apr 16, 2026Update langextract requirement from >=1.0.0 to >=1.2.1 in /presidio-analyzer — vjk7989/glowing-train0 reactions · 6 comments
- Apr 16, 2026Integration: Add langextract as a local visual trace layer (observability HTML viewer + CLI) — MervinPraison/PraisonAI0 reactions · 1 comment
- Apr 15, 2026Update langextract requirement from >=1.0.0 to >=1.2.1 in /presidio-analyzer — AskhatSBK/PII_encrypter0 reactions · 1 comment
- Apr 14, 2026build(deps-dev): Update langextract requirement from >=1.0.0 to >=1.2.1 in /presidio-analyzer — valentinvl1/anonymous0 reactions · 1 comment
- Apr 12, 2026build(deps-dev): update langextract requirement from >=1.0.0 to >=1.2.1 in /presidio-analyzer — data-privacy-stack/presidio0 reactions · 9 comments
- Mar 13, 2026docs: LangExtract(Google) LLM 기반 정보 추출 라이브러리 심층 기술 분석 — sangyun628/research0 reactions
- Mar 3, 2026[Feature]: Add PageIndex and LangExtract for Enhanced RAG and Information Extraction — Harmeet10000/AgentNexus-LangChain-FastAPI0 reactions · 3 comments
- Feb 19, 2026feat(tools): Add LangExtract tool for structured information extraction — google/adk-python-community0 reactions · 3 comments
- Feb 19, 2026feat: Add LangExtract tool for structured information extraction — google/adk-python-community0 reactions
- Feb 19, 2026feat: Add LangExtract tool integration for structured information extraction — google/adk-python0 reactions · 2 comments
- Feb 15, 2026feat(repair-log-in-diagnostics): add typed run-level repair log entries — Ismail-elkorchi/ekchylisma0 reactions
- Feb 15, 2026feat(provider-structured-generate-split): split generate and generateStructured paths — Ismail-elkorchi/ekchylisma0 reactions
- Feb 15, 2026feat(multi-pass-execution-model): implement deterministic multi-pass shard execution — Ismail-elkorchi/ekchylisma0 reactions
- Feb 15, 2026build(semantic-identifiers-and-placeholder-ban): enforce semantic identifier grammar and semantic cage checks — Ismail-elkorchi/ekchylisma0 reactions
- Jan 14, 2026Feat/chunking extractor — DFKI-NLP/kibad-llm0 reactions · 13 comments
- Jan 6, 2026Add LangExtract backend support for sem_extract — oneryalcin/lotus0 reactions
- Dec 22, 2025LangExtract — droq-ai/dfx-hf-models-node0 reactions
- Dec 8, 2025deps(deps): bump langextract from 1.0.7 to 1.1.1 — LM-150A/docflash0 reactions
- Nov 17, 2025deps(deps): bump langextract from 1.0.7 to 1.1.0 — LM-150A/docflash0 reactions · 1 comment
- Oct 13, 2025deps(deps): bump langextract from 1.0.7 to 1.0.9 — LM-150A/docflash0 reactions · 1 comment
- Oct 7, 2025Explore LangExtract as a backend — NatLabRockies/COMPASS0 reactions · 1 comment
- Sep 24, 2025Try langextract — UW-Madison-DSI/wsmb-meta0 reactions · 1 comment
- Sep 7, 2025LangExtract 格式化文本数据 — cisen/blog0 reactions
- Sep 3, 2025How to preprocess [unstructured files] such as pdf for LLM+RAG? — xp1632/Aalen_working_log0 reactions · 1 comment
On Bluesky · 24
- Jul 31, 2025Google LangExtract: A Gemini powered information extraction library Process large volumes of unstructured text into structured information… — @sungkim.bsky.social23 likes and reposts
- Feb 10, 2026langextract: A Python library for extracting structured information from unstructured text using LLMs with precise source grounding and… — @stephenturner.us6 likes and reposts
- Jan 16, 2026🚀 Skyrocketing! 🚀 (200+ new stars) 📦 google / langextract ⭐ 20,953 (+329) 🗒 Python A Python library for extracting structured… — @github-trending.bsky.social5 likes and reposts
- Dec 23, 2025LangExtract : une lib Open Source écrite en Python par Google permettant d'extraire automatiquement des données structurées depuis des… — @bearstech.com5 likes and reposts
- Aug 6, 2025LangExtract A Python library for extracting structured information from unstructured text using LLMs with precise source grounding and… — @pythonhub.dev5 likes and reposts
19 more on Bluesky
- Feb 10, 2026¿Qué hace, en simple? -Lee documentos enormes (100+ páginas) -Extrae la información importante -Te dice exactamente de dónde sale cada dato… — @jesusgallent.com4 likes and reposts
- Feb 7, 2026LangExtract by Google: extract structured data from text with Python 🧩 LLM-powered parsing → clean schemas from messy inputs 🤖 📜 Apache… — @qdrddr.bsky.social3 likes and reposts
- Aug 18, 2025A Python library for extracting structured information from unstructured text using LLMs with precise source grounding and interactive… — @francescalazzeri.bsky.social3 likes and reposts
- Aug 4, 2025I saw this new Langextract OS library google wrote for python and couldn't help but thinking that this is a great use case for an R… — @yannco.bsky.social3 likes and reposts · 1 reply
- Aug 3, 2025LangExtract: Python library for extracting structured data from language models | Discussion — @hackernewsbot.bsky.social2 likes and reposts
- Jul 31, 2025GitHub - google/langextract: A Python library for extracting structured information from unstructured text using LLMs with precise source… — @tech-trending.bsky.social2 likes and reposts
- Feb 12, 2026💎 Hidden Gem! 💎 (1000+ new stars) 📦 google / langextract ⭐ 31,064 (+1,201) 🗒 Python A Python library for extracting structured… — @github-trending.bsky.social1 likes and repost · 1 reply
- Feb 12, 2026github.com/google/lange... pot ser molt útil per molts projectes — @rogerserra.bsky.social1 likes and repost
- Feb 10, 2026Could be mixed in with structured text extraction using: github.com/google/lange... — @stungeye.com1 likes and repost
- Feb 9, 2026Google's LangExtract turns messy documents into structured data using LLMs, with precise source grounding that shows exactly where each… — @arifsolmaz.bsky.social1 likes and repost
- Feb 8, 2026🚀 Skyrocketing! 🚀 (200+ new stars) 📦 google / langextract ⭐ 24,557 (+430) 🗒 Python A Python library for extracting structured… — @github-trending.bsky.social1 likes and repost · 1 reply
- Jan 20, 2026🎉 Celebrating! 🎉 (500+ new stars) 📦 google / langextract ⭐ 23,016 (+566) 🗒 Python A Python library for extracting structured… — @github-trending.bsky.social1 likes and repost · 1 reply
- Aug 31, 2025Spændende github.com/google/lange... — @kasperjunge.bsky.social1 likes and repost
- Aug 11, 2025Google released “LangExtract” - A Python library for extracting structured information from unstructured text using LLMs with precise… — @engineersmeetai.substack.com1 likes and repost
- Jul 16, 2026公式のLangExtractは、抽出結果を原文の位置へ結び、確認しやすくするPythonライブラリ。長文を分割・並列・複数パスで扱う設計も、実務的でかなり良い。 https://github.com/google/langextract… — @sara-echosphere.bsky.social0 likes and reposts · 1 reply
- Apr 16, 2026Hot! github.com/google/lange... — @metamind42.bsky.social0 likes and reposts · 1 reply
- Feb 8, 2026https://b23.tv/BV143ewzpEM4 https://github.com/google/langextract 谷歌开源项目还是不会让人失望的,无论是Google还是GoogleChromelabs。… — @admin.mstdn.feddit.social.ap.brid.gy0 likes and reposts · 2 replies
- Sep 5, 2025Github Repo: github.com/google/lang... — @arindam-1729.bsky.social0 likes and reposts · 1 reply
- Aug 4, 2025LangExtract: Python library for extracting structured data from language models View Article | Join the HN Conversation Summary of HN… — @hncompanion.com0 likes and reposts · 1 reply
On Hacker News · 1
- Jul 30, 2025LangExtract: Python library for extracting structured data from language models166 points · 14 comments
The file
Files
LangExtract Usage
LangExtract extracts structured information from unstructured text using LLMs.
The main entry point is lx.extract(). Every extraction needs at least one
example and input text. prompt_description is optional but recommended.
Install
pip install langextract
# For OpenAI model support:
pip install langextract[openai]API keys
# Gemini (checks GEMINI_API_KEY then LANGEXTRACT_API_KEY)
export GEMINI_API_KEY="your_key"
# OpenAI (checks OPENAI_API_KEY then LANGEXTRACT_API_KEY)
export OPENAI_API_KEY="your_key"
# Ollama: no API key needed, just a running Ollama serverAuto-routing + env-default resolution is tuned for GPT-style model IDs
(gpt-4*, gpt-5*). For OpenAI-compatible endpoints or non-GPT IDs,
pass an explicit ModelConfig — see references/providers.md.
Basic extraction
import langextract as lx
examples = [
lx.data.ExampleData(
text="Patient takes lisinopril 10mg daily for hypertension.",
extractions=[
lx.data.Extraction(
extraction_class="medication",
extraction_text="lisinopril",
attributes={"dose": "10mg", "frequency": "daily"},
),
lx.data.Extraction(
extraction_class="condition",
extraction_text="hypertension",
attributes={"status": "active"},
),
],
)
]
result = lx.extract(
text_or_documents="Patient is prescribed metformin 500mg twice daily.",
prompt_description="Extract medications and conditions with attributes.",
examples=examples,
model_id="gemini-2.5-flash",
)
for e in result.extractions:
print(e.extraction_class, e.extraction_text)
print(f" char_interval: {e.char_interval}")
print(f" attributes: {e.attributes}")See examples/basic_extraction.py for a runnable version and
examples/relationship_extraction.py for using extraction_class +
attributes to encode relationships between entities.
Writing good examples
Examples drive model behavior. Follow these rules:
extraction_textmust be verbatim from the example text, not paraphrased- List extractions in order of appearance in the text
- Each
extraction_classshould be consistent across examples - Include attributes that match what you want extracted at runtime
LangExtract can raise prompt-alignment warnings when an example's
extraction_text values don't align cleanly to the example's text
(failed alignment, or fuzzy/lesser rather than exact). The validator does
not enforce rules 2–4 above — those are guidance to steer the model's
output, not checked invariants.
To fail fast on alignment issues during development, pass these kwargs
directly to lx.extract() (both default to permissive):
from langextract.prompt_validation import PromptValidationLevel
result = lx.extract(
...,
prompt_validation_level=PromptValidationLevel.ERROR, # default: WARNING
prompt_validation_strict=True, # default: False
)See references/prompt-validation.md for level semantics and strict-mode
behavior.
Key parameters
result = lx.extract(
text_or_documents=text, # str, URL, or list of Documents
prompt_description=prompt, # what to extract (optional)
examples=examples, # few-shot examples (required)
model_id="gemini-2.5-flash", # model to use
extraction_passes=1, # >1 for higher recall (costs more)
max_char_buffer=1000, # chunk size
batch_length=10, # chunks per batch
max_workers=10, # parallel workers (provider-dependent)
context_window_chars=None, # cross-chunk context for coreference
)text_or_documentsaccepts a URL string (fetch_urls=True by default).- For full parallelism, keep
batch_length >= max_workers. Parallel processing viamax_workersis provider-dependent; some providers parallelize batched prompts, while others (such as the current Ollama provider) process them sequentially. context_window_charsincludes characters from the previous chunk as context for the current one, which helps with coreference and entity continuity across chunk boundaries.- For multiple documents, pass a list of
lx.data.Document— seeexamples/multiple_documents.py.
Working with results
# Filter to grounded extractions only (have source positions)
grounded = [e for e in result.extractions if e.char_interval]
# Access source position
for e in grounded:
start = e.char_interval.start_pos
end = e.char_interval.end_pos
matched_text = result.text[start:end]
# Save to JSONL
lx.io.save_annotated_documents(
[result], output_name="results.jsonl", output_dir="."
)
# Visualize from JSONL (shows first document)
html = lx.visualize("results.jsonl")
with open("visualization.html", "w") as f:
if hasattr(html, "data"):
f.write(html.data) # Jupyter/Colab
else:
f.write(html)
# Or visualize an AnnotatedDocument directly
html = lx.visualize(result)Provider selection
The default is Gemini. For other providers, see references/providers.md,
which covers:
- OpenAI (JSON mode; fence behavior auto-configured)
- Ollama (local models,
model_url) ModelConfigfor advanced provider_kwargs (custombase_url, etc.)- Custom provider plugins via
router.register()
Common issues
Extractions with char_interval=None: the extraction could not be
located in the source text. Common causes include paraphrased output,
alignment misses, or hallucinated entities. Filter with
[e for e in result.extractions if e.char_interval]. To tune alignment,
see references/resolver-params.md.
Prompt alignment warnings: your examples have extraction_text that
doesn't match the example text verbatim. Fix the examples, or see
references/prompt-validation.md to fail fast during development.
Slow on long documents: extraction_passes > 1 multiplies processing
time. Start with 1 and increase only if recall is insufficient.
Model selection: gemini-2.5-flash is recommended for most tasks;
gemini-2.5-pro for complex reasoning.
Further reading
references/providers.md— OpenAI, Ollama, ModelConfig, custom pluginsreferences/resolver-params.md— fuzzy alignment tuningreferences/prompt-validation.md— catching example issues earlyexamples/— runnable scripts for each scenario above
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

