gitwtfhub

wtf is langextract?

google/langextract — explained in plain English

Analysis updated 2026-05-18

36,390PythonAudience · developerComplexity · 2/5LicenseSetup · moderate

TL;DR

Python library that uses LLMs to extract structured data from unstructured text documents, with source grounding and interactive visualization.

Mindmap

mindmap
  root((LangExtract))
    What it does
      Extract entities from text
      Map to source locations
      Visualize results
    How it works
      Plain English prompts
      Few-shot examples
      LLM processing
    Features
      Chunk long documents
      Parallel processing
      Multi-pass extraction
    Supported models
      Google Gemini
      OpenAI models
      Ollama local models
    Use cases
      Clinical notes
      Legal contracts
      Literary analysis

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Why would anyone build with this?

REASON 1

Extract medications and dosages from clinical notes and automatically populate a database.

REASON 2

Pull key terms, obligations, and parties from legal contracts for compliance review.

REASON 3

Identify characters, relationships, and plot events from literary texts for analysis.

REASON 4

Extract structured data from domain-specific documents without training a custom model.

What's in the stack?

PythonGoogle Gemini APIOpenAI APIOllama

How it stacks up

google/langextractmyshell-ai/openvoicehankcs/hanlp
Stars36,39036,46336,296
LanguagePythonPythonPython
Setup difficultymoderatehardmoderate
Complexity2/54/53/5
Audiencedeveloperdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you spin it up?

Difficulty · moderate Time to first run · 30min

Requires API key from Google Gemini or OpenAI, or local Ollama setup.

Use freely for any purpose including commercial. Keep the notice and disclose changes to the patent grant.

Wtf does this do

LangExtract is a Python library from Google that uses large language models (LLMs) to pull structured information out of unstructured text documents. "Structured information" means organized, categorized data, like a table of named entities, a list of medications with dosages, or characters and their relationships, drawn from a free-form document like a clinical note, a legal contract, or a literary text. This solves the gap between the unstructured world (documents written in natural language) and the structured world (databases, spreadsheets, analytics pipelines) that applications need. The library works by letting you describe your extraction task using plain English instructions and a few hand-crafted examples that show the model what you want. You provide a text document, your prompt description, and your examples, and LangExtract sends everything to an LLM and returns the extracted entities as structured Python objects. A key feature is precise source grounding: every extracted item is mapped back to its exact character position in the original text. This lets the library generate an interactive HTML visualization where you can see each extraction highlighted in context, making it easy to verify that the model stayed faithful to the source rather than hallucinating. For long documents, the library handles chunking the text into manageable pieces, processing chunks in parallel, and running multiple passes to improve recall (the proportion of relevant items actually found). It supports Google Gemini models by default, including Gemini Flash and Gemini Pro, but also works with OpenAI models and local open-source models running via Ollama. You would use LangExtract when you need to extract entities from clinical notes, radiology reports, contracts, or any domain-specific text without fine-tuning a model. The tech stack is Python, primarily targeting the Gemini API, and distributed as a pip package.

Yoink these prompts

Prompt 1
Use LangExtract to extract all medication names and dosages from this clinical note, with source locations highlighted in an interactive HTML view.
Prompt 2
Show me how to set up LangExtract with Google Gemini to extract named entities (people, organizations, locations) from a batch of news articles.
Prompt 3
How do I use LangExtract to extract contract terms and obligations from a PDF, then verify the extractions are grounded in the original text?
Prompt 4
Extract character relationships and plot events from a novel chapter using LangExtract with few-shot examples, then visualize the results.
Prompt 5
Configure LangExtract to process a long document by chunking it, running parallel extraction, and merging results to improve recall.

Frequently asked questions

wtf is langextract?

Python library that uses LLMs to extract structured data from unstructured text documents, with source grounding and interactive visualization.

What language is langextract written in?

Mainly Python. The stack also includes Python, Google Gemini API, OpenAI API.

What license does langextract use?

Use freely for any purpose including commercial. Keep the notice and disclose changes to the patent grant.

How hard is langextract to set up?

Setup difficulty is rated moderate, with roughly 30min to a first successful run.

Who is langextract for?

Mainly developer.

View the repo → Decode another repo

This repo across BitVibe Labs

Don't trust strangers blindly. Verify against the repo.