!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/)
            
            *   [Use reference examples](/v0.1/docs/use_cases/extraction/how_to/examples/)
            *   [Handle long text](/v0.1/docs/use_cases/extraction/how_to/handle_long_text/)
            *   [Handle Files](/v0.1/docs/use_cases/extraction/how_to/handle_files/)
            *   [Without function calling](/v0.1/docs/use_cases/extraction/how_to/parse/)
        *   [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](/v0.1/docs/use_cases/extraction/)
*   How-To Guides
*   Handle Files

Handle Files
============

Besides raw text data, you may wish to extract information from other file types such as PowerPoint presentations or PDFs.

The general strategy is to use a LangChain [document loader](/v0.1/docs/modules/data_connection/document_loaders/) or other method to parse files into a text format that can be fed into LLMs.

LangChain features a large number of [document loader integrations](/v0.1/docs/integrations/document_loaders/).

Let’s go over an example of loading and extracting data from a PDF. First, we install required dependencies:

tip

See [this section for general instructions on installing integration packages](/v0.1/docs/get_started/installation/#installing-integration-packages).

*   npm
*   yarn
*   pnpm

    npm i @langchain/openai zod

    yarn add @langchain/openai zod

    pnpm add @langchain/openai zod

    import { PDFLoader } from "langchain/document_loaders/fs/pdf";// Only required in a Deno notebook environment to load the peer dep.import "pdf-parse";const loader = new PDFLoader("./test/data/bitcoin.pdf");const docs = await loader.load();

    [Module: null prototype] { default: [AsyncFunction: PDF] }

Now that we’ve loaded a PDF document, let’s try extracting mentioned people. We can define a schema like this:

    import { z } from "zod";const personSchema = z  .object({    name: z.optional(z.string()).describe("The name of the person"),    hair_color: z      .optional(z.string())      .describe("The color of the person's hair, if known"),    height_in_meters: z      .optional(z.string())      .describe("Height measured in meters"),    email: z.optional(z.string()).describe("The person's email, if present"),  })  .describe("Information about a person.");const peopleSchema = z.object({  people: z.array(personSchema),});

And then initialize our extraction chain like this:

    import { ChatPromptTemplate } from "@langchain/core/prompts";import { ChatOpenAI } from "@langchain/openai";const SYSTEM_PROMPT_TEMPLATE = `You are an expert extraction algorithm.Only extract relevant information from the text.If you do not know the value of an attribute asked to extract, you may omit the attribute's value.`;const prompt = ChatPromptTemplate.fromMessages([  ["system", SYSTEM_PROMPT_TEMPLATE],  ["human", "{text}"],]);const llm = new ChatOpenAI({  model: "gpt-4-0125-preview",  temperature: 0,});const extractionRunnable = prompt.pipe(  llm.withStructuredOutput(peopleSchema, { name: "people" }));

Now, let’s try invoking it!

    await extractionRunnable.invoke({ text: docs[0].pageContent });

    { people: [ { name: "Satoshi Nakamoto", email: "satoshin@gmx.com" } ] }

* * *

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

[

Previous

Handle long text

](/v0.1/docs/use_cases/extraction/how_to/handle_long_text/)[

Next

Without function calling

](/v0.1/docs/use_cases/extraction/how_to/parse/)

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.