LangExtract: Mining structured data from clinical notes
This article explores Google's LangExtract as a potential method for extracting structured data from unstructured text in health and other domains.
Introduction
A great deal of valuable health data sits in unstructured clinical notes. Unstructured text may be useful in its immediate context but it creates issues for subsequent machine processing, health data exchange, and downstream analytics.
Google's LangExtract is an open-source python library that supports extracting structured information from unstructured text using carefully instructed LLMs. While LangExtract can support this kind of Natural Language Processing across many domains, its origins are in health data extraction, and LangExtract is a component of Google's Health AI Developer Foundations.

In this post I'll outline LangExtract's background, and what it does. Then I'll talk about risks and provide links to recent research examples incorporating LangExtract in both medical and non-medical domains.
Background
LangExtract has its origins in a 2023 paper by Akshay Goel et al., called LLMs Accelerate Annotation for Medical Information Extraction. The paper focused on identification or "annotation" of medication details in unstructured discharge summary text.
The problem falls under the heading of Natural Language Processing, and in particular, Named Entity Recognition and Relation Extraction.
As the authors note, there are several approaches to this problem but training or fine-tuning specialist models can require significant human and computational resource. Their question was not: Are LLMs better at this task? The question was whether a generalist LLM could perform the task usefully, without the need to train or fine-tune a specialist model.
The authors found that an LLM (PaLM 2) was able to perform first-pass identification of medication details at a quality comparable to its human counterparts, while reducing human annotation time by 58% on average.
Below is a simple example from the study. We see the recognised entities (medication dose, mode, name, etc.), and their relationships clustered as entry-1 and entry-2.

This study was to provide many of the core ideas behind the development of LangExtract itself.
Enter LangExtract
On July 30, 2025 a post on Google for Developers announced the release of LangExtract on GitHub. Its description (with my emphasis) is:
LangExtract is a Python library that uses Large Language Models (LLMs) to extract structured information from unstructured text documents based on user-defined instructions. It processes materials such as clinical notes or reports, identifying and organizing key details while ensuring the extracted data corresponds to the source text through precise source grounding and visual highlighting.
Source grounding
LangExtract does not treat the LLM as a 'black box'. Instead, each decision the LLM makes about how the data is structured is traceable back to exact character (and token) positions in the source text. We can see this highlighted below in the LangExtract "RadExtract" demonstration example, where the resulting structured data includes 'start_pos' and 'end_pos' to identify the source text informing the extraction.

LangExtract also includes the ability to generate interactive HTML visualisations of an extraction. Various human-in-the-loop approaches are made possible through this essential 'source grounding' feature.
Batteries not included
LangExtract as an orchestration tool that enacts the configurations and LLM instructions provided by the user. As the scale, complexity, and requirements for accuracy increase, so do the number of critical considerations. I'll cover just some of the important user inputs to LangExtract briefly below.
Choice of LLM
Out of the box, LangExtract can connect to Gemini and OpenAI LLMs via their APIs, or to locally hosted LLMs via Ollama. LangExtract also provides the ability to create custom LLM provider plugins.
It goes without saying that with real health data, satisfying privacy and data sovereignty requirements is of supreme importance. So where the LLM is, and what protections sit around it are essential considerations. Beyond those considerations, it's clear that the LLM must have sufficient world knowledge for the task at hand. That includes the need for knowledge of locally relevant names, symbols, abbreviations and so on – or a reliable approach to making that local knowledge available to the LLM. Fine-tuning an existing model with a technique like LoRA could potentially be warranted in some New Zealand use cases.
LangExtract also implements Controlled Generation (advanced output schema enforcement) for supported models, but not currently via Ollama. I have not yet explored whether a custom LLM provider plugin might circumvent this limitation for Ollama-hosted LLMs that have the necessary capabilities.
Few-shot prompts
At the heart of the LangExtract approach is a user-defined prompt.
The prompt asks the LLM to examine some input text, identify specific "entities" (e.g. medications, dosages etc.), and their relationships if desired. Central to the approach is "few-shot" prompt engineering that presents examples of inputs and required outputs to the LLM. The Python below shows a LangExtract example snippet with only one example provided to the LLM. A more complex demonstration few-shot prompt is available here).

Other decisions
The call to extract() (near the bottom of the screenshot above) accepts several parameters that are not included in that snippet. The following are some examples. For longer input text that needs to be chunked, max_char_buffer sets the maximum size of each chunk of text the LLM is presented with. A parameter called context_window_chars includes a fixed number of characters from the previous chunk as additional context (which can be especially useful for Relation Extraction). An extraction_passes parameter enables multiple passes of the same input text.
What happens inside
Below is a high-level description of what happens once extract()is called. In this description I'm considering larger input text that requires multi-chunk and perhaps multi-pass processing:
extraction.pyfirst runs prompt validation (prompt_validation.py) to check that the prompt example(s) can be aligned to the example input text.prompting.pycreates aPromptTemplateStructuredthat will later be rendered for every chunk.factory.pyinstantiates the LLM, combining user-provided settings withproviderdefaults.- A
FormatHandleris configured and aResolveris created which will later parse LLM output intoExtractionobjects. - An
Annotatoris created with the model, prompt template and format handler.
annotation.py then runs the core loop. It chunks the input text (chunking.py + tokenizer.py) according to max_char_buffer. Then for each chunk (and across sequential passes when extraction_passes > 1):
- The prompt is rendered from the prompt template + the current chunk (optionally with a short context window from the previous chunk).
- The LLM is called with the rendered prompt and returns structured output.
- The
Resolverparses the LLM output intoExtractionobjects and aligns/grounds them back to the source text.
Results from multiple chunks (and non-overlapping results from multiple passes) are merged into one or more AnnotatedDocument objects. These are saved as JSONL and can be used as input to the interactive HTML visualiser.
Risks
Just the mention of using an LLM for clinical data extraction could raise alarm. That could be a barrier for decision makers considering this approach. However, caution is an appropriate starting point when it comes to health informatics – more so when it comes to the use of AI, or indeed, any 'shiny new thing'.
Decisions about exploring tools like LangExtract need to be centred on the individual use case and how it can be proven that the technique is (or is not) suitable and safe for that use case. LangExtract's, source grounding and support for human-in-the-loop validation make errors discoverable and traceable. Those errors can inform either refinement or abandonment of the approach in any given use case.
In the context of health, at one end LangExtract could be used to analyse social media posts about health conditions to support public health interventions. At the other end, it could be used to extract data from a clinical note that later informs a clinical decision about you. The risks are different at each end of the continuum, as are the protections that need to be in place in each case. Similar to government application of AI more broadly, public interest, and the public's need for assurance increases as various applications of AI move closer to impacting the individual.
Reception to date
It's been just over a year since LangExtract's release so I'll be interested to track its evolving reception in the medical literature. In the meantime I see examples like Selivanov et al. (2026) where LangExtract was used to extract phenotype data from the output of a specialist ECG-LLM. Zheng et al. (2026) included LangExtract as a tool in an experimental agentic medical coding workflow. Ningtyas et al. (2026) assessed its use in an annotation pipeline for Medical Concept Normalisation.
While LangExtract has its origins in health data extraction, it's also gaining significant interest beyond health. Because LangExtract can leverage generalist LLMs with broad world knowledge, it has the potential to lower the bar for Named Entity Recognition and Relation Extraction across diverse domains.
Outside health I see papers like Yoon & Kim (2025) who explored LangExtract for information extraction in complex cybercrime investigation. Liu et al. (2026) used LangExtract for relationship parsing in research on protecting personally identifiable information. Teo et al. (2026) describe using LangExtract for knowledge engineering and process mapping for Total Airport Management.
In the developer community, LangExtract is being discussed as a way to extract entities and relationships for knowledge-graph construction in GraphRAG pipelines (e.g. this article by M. K. Pravin Kumar). However, time constraints make that a topic for another day.
Closing questions
- Have you got a problem that could be improved by extracting structured data from unstructured text?
- What are your thoughts on LangExtract?
- Are you using it, or exploring its potential use?
Whether you're in health or another domain, I love to chat about data and AI. Please feel free to reach out to me on LinkedIn or via this contact form.
References
Goel, A., Lehman, E., Gulati, A., Chen, R., Nori, H., Hager, G. D., & Durr, N. J. (2023). LLMs Accelerate Annotation for Medical Information Extraction. Machine Learning for Health (ML4H), PMLR. arXiv:2312.0229
Goel, A. (2025). LangExtract. Zenodo.
Goel, A., & Kiraly, A. (2025, July 30). Introducing LangExtract: A Gemini powered information extraction library. Google Developers Blog.
Kumar, M. K. P. (2026, June 25). A practical GraphRAG architecture using LangExtract, Neo4j, Qdrant, and Ollama. Stackademic.
Liu, S., Fan, W., & Xu, Y. (2026). Shielding PII to Prevent Re-identification and Preserve Utility. Proceedings of the ACM on Management of Data, 4(3 (SIGMOD), 1-28.
Ningtyas, A. M., Herwanto, G. B., Sari, Y., Putri, R. A., Kovacevic, F., El-Ebshihy, A., ... & Piroi, F. (2026, July). AnnoHID: LLM-Assisted Annotation Framework for Low-Resource Medical Texts. In Proceedings of the 64th Annual Meeting of the Association for Computational Linguistics (Volume 3: System Demonstrations) (pp. 683-691).
Selivanov, A., Jungmann, F., Kehrer, J., Laugwitz, K. L., Martens, E., & Rueckert, D. (2026). ECG-LLM: Foundation Model for ECG-Based Cardiac Reasoning. arXiv preprint arXiv:2607.16323.
Teo, D., Sam, A., Koh, C. S. M., Nagi, R., & Ribeiro, N. A. (2026). Semi-Automated Knowledge Engineering and Process Mapping for Total Airport Management. arXiv preprint arXiv:2603.26076.
Yoon, B., & Kim, J. (2025). Self-verification-based framework for key information extraction from unstructured text: A cybercrime investigation support perspective. Journal of Data Forensics Research, 143-159.
Zheng, J., Nassar, I., Vu, T., Zhong, X., Lin, Y., Liu, T., ... & Li, Y. F. (2026, July). Meddcr: Learning to design agentic workflows for medical coding. In Findings of the Association for Computational Linguistics: ACL 2026 (pp. 12878-12893).