!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=new URLSearchParams(window.location.search).get("docusaurus-theme")}catch(t){}return t}()||function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}(),document.documentElement.setAttribute("data-announcement-bar-initially-dismissed",function(){try{return"true"===localStorage.getItem("docusaurus.announcement.dismiss")}catch(t){}return!1}())

[Skip to main content](#__docusaurus_skipToContent_fallback)

LangChain v0.2 is coming soon! Preview the new docs [here](/v0.2/docs/introduction/).

[

![🦜️🔗 Langchain](/v0.1/img/brand/wordmark.png)![🦜️🔗 Langchain](/v0.1/img/brand/wordmark-dark.png)

](/v0.1/)[Docs](/v0.1/docs/get_started/introduction/)[Use cases](/v0.1/docs/use_cases/)[Integrations](/v0.1/docs/integrations/platforms/)[API Reference](https://api.js.langchain.com)

[More](#)

*   [People](/v0.1/docs/people/)
*   [Community](/v0.1/docs/community/)
*   [Tutorials](/v0.1/docs/additional_resources/tutorials/)
*   [Contributing](/v0.1/docs/contributing/)

[v0.1](#)

*   [v0.2](https://js.langchain.com/v0.2/docs/introduction)
*   [v0.1](/v0.1/docs/get_started/introduction/)

[🦜🔗](#)

*   [LangSmith](https://smith.langchain.com)
*   [LangSmith Docs](https://docs.smith.langchain.com)
*   [LangChain Hub](https://smith.langchain.com/hub)
*   [LangServe](https://github.com/langchain-ai/langserve)
*   [Python Docs](https://python.langchain.com/)

[Chat](https://chatjs.langchain.com)[](https://github.com/langchain-ai/langchainjs)

Search

*   [Use cases](/v0.1/docs/use_cases/)
    
    *   [SQL](/v0.1/docs/use_cases/sql/)
        
    *   [Chatbots](/v0.1/docs/use_cases/chatbots/)
        
    *   [Extraction](/v0.1/docs/use_cases/extraction/)
        
        *   [Quickstart](/v0.1/docs/use_cases/extraction/quickstart/)
        *   [How-To Guides](/v0.1/docs/use_cases/extraction/how_to/examples/)
            
        *   [Guidelines](/v0.1/docs/use_cases/extraction/guidelines/)
    *   [Query Analysis](/v0.1/docs/use_cases/query_analysis/)
        
    *   [Q&A with RAG](/v0.1/docs/use_cases/question_answering/)
        
    *   [Tool use](/v0.1/docs/use_cases/tool_use/)
        
    *   [Interacting with APIs](/v0.1/docs/use_cases/api/)
    *   [Tabular Question Answering](/v0.1/docs/use_cases/tabular/)
    *   [Graphs](/v0.1/docs/use_cases/graph/)
        
    *   [Summarization](/v0.1/docs/use_cases/summarization/)
    *   [Agent Simulations](/v0.1/docs/use_cases/agent_simulations/)
        
    *   [Autonomous Agents](/v0.1/docs/use_cases/autonomous_agents/)
        
    *   [Code Understanding](/v0.1/docs/use_cases/code_understanding/)
    *   [Audio/Video Structured Extraction](/v0.1/docs/use_cases/media/)

*   [](/v0.1/)
*   [Use cases](/v0.1/docs/use_cases/)
*   Extraction

On this page

Extraction
==========

Overview[​](#overview "Direct link to Overview")
------------------------------------------------

Large Language Models (LLMs) are emerging as an extremely capable technology for powering information extraction applications.

Classical solutions to information extraction rely on a combination of people, (many) hand-crafted rules (e.g., regular expressions), and custom fine-tuned ML models.

Such systems tend to get complex over time and become progressively more expensive to maintain and more difficult to enhance.

LLMs can be adapted quickly for specific extraction tasks just by providing appropriate instructions to them and appropriate reference examples.

This guide will show you how to use LLMs for extraction applications!

Approaches[​](#approaches "Direct link to Approaches")
------------------------------------------------------

There are 3 broad approaches for information extraction using LLMs:

*   **Tool/Function Calling** Mode: Some LLMs support a _tool or function calling_ mode. These LLMs can structure output according to a given **schema**. Generally, this approach is the easiest to work with and is expected to yield good results.
    
*   **JSON Mode**: Some LLMs can be forced to output valid JSON. This is similar to **tool/function calling** approach, except that the schema is provided as part of the prompt. Generally, our intuition is that this performs worse than a **tool/function calling** approach, especially for complex schemas, but you should verify for your own use case!
    
*   **Prompting Based**: LLMs that can follow instructions well can be instructed to generate text in a desired format. The generated text can be parsed downstream using existing [Output Parsers](/v0.1/docs/modules/model_io/output_parsers/) or using [custom parsers](/v0.1/docs/modules/model_io/output_parsers/custom/) into a structured format like JSON. This approach can be used with LLMs that **do not support** JSON mode or tool/function calling modes. This approach is more broadly applicable, though may yield worse results than models that have been fine-tuned for extraction or function calling.
    

Quickstart[​](#quickstart "Direct link to Quickstart")
------------------------------------------------------

Head to the [quickstart](/v0.1/docs/use_cases/extraction/quickstart/) to see how to extract information using LLMs using a basic end-to-end example.

The quickstart focuses on information extraction using the **tool/function calling** approach.

How-To Guides[​](#how-to-guides "Direct link to How-To Guides")
---------------------------------------------------------------

*   [Use Reference Examples](/v0.1/docs/use_cases/extraction/how_to/examples/): Learn how to use **reference examples** to improve performance.
*   [Handle Long Text](/v0.1/docs/use_cases/extraction/how_to/handle_long_text/): What should you do if the text does not fit into the context window of the LLM?
*   [Handle Files](/v0.1/docs/use_cases/extraction/how_to/handle_files/): Examples of using LangChain document loaders and parsers to extract from files like PDFs.
*   [Use a Parsing Approach](/v0.1/docs/use_cases/extraction/how_to/parse/): Use a prompt based approach to extract with models that do not support **tool/function calling**.

Guidelines[​](#guidelines "Direct link to Guidelines")
------------------------------------------------------

Head to the [Guidelines](/v0.1/docs/use_cases/extraction/guidelines/) page to see a list of opinionated guidelines on how to get the best performance for extraction use cases.

Other Resources[​](#other-resources "Direct link to Other Resources")
---------------------------------------------------------------------

*   The [output parser](/v0.1/docs/modules/model_io/output_parsers/) documentation includes various parser examples for specific types (e.g., lists, datetime, enum, etc).
*   LangChain [document loaders](/v0.1/docs/modules/data_connection/document_loaders/) to load content from files. Please see list of [integrations](/v0.1/docs/integrations/document_loaders/).
*   The experimental [Anthropic function calling](/v0.1/docs/integrations/chat/anthropic_tools/) support provides similar functionality to Anthropic chat models.
*   [Ollama](/v0.1/docs/integrations/chat/ollama/) natively supports JSON mode, making it easy to output structured content using local LLMs
*   [OpenAI’s function and tool calling](https://platform.openai.com/docs/guides/function-calling) guide.
*   [OpenAI’s JSON mode](https://platform.openai.com/docs/guides/text-generation/json-mode) guide.

* * *

#### Help us out by providing feedback on this documentation page:

[

Previous

Tool usage

](/v0.1/docs/use_cases/chatbots/tool_usage/)[

Next

Quickstart

](/v0.1/docs/use_cases/extraction/quickstart/)

*   [Overview](#overview)
*   [Approaches](#approaches)
*   [Quickstart](#quickstart)
*   [How-To Guides](#how-to-guides)
*   [Guidelines](#guidelines)
*   [Other Resources](#other-resources)

Community

*   [Discord](https://discord.gg/cU2adEyC7w)
*   [Twitter](https://twitter.com/LangChainAI)

GitHub

*   [Python](https://github.com/langchain-ai/langchain)
*   [JS/TS](https://github.com/langchain-ai/langchainjs)

More

*   [Homepage](https://langchain.com)
*   [Blog](https://blog.langchain.dev)

Copyright © 2024 LangChain, Inc.