!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

*   [Get started](/v0.1/docs/get_started/)
    
    *   [Introduction](/v0.1/docs/get_started/introduction/)
    *   [Installation](/v0.1/docs/get_started/installation/)
    *   [Quickstart](/v0.1/docs/get_started/quickstart/)
*   [LangChain Expression Language](/v0.1/docs/expression_language/)
    
    *   [Get started](/v0.1/docs/expression_language/get_started/)
    *   [Why use LCEL?](/v0.1/docs/expression_language/why/)
    *   [Interface](/v0.1/docs/expression_language/interface/)
    *   [Streaming](/v0.1/docs/expression_language/streaming/)
    *   [How to](/v0.1/docs/expression_language/how_to/routing/)
        
    *   [Cookbook](/v0.1/docs/expression_language/cookbook/)
        
    *   [LangChain Expression Language (LCEL)](/v0.1/docs/expression_language/)
*   [Modules](/v0.1/docs/modules/)
    
    *   [Model I/O](/v0.1/docs/modules/model_io/)
        
        *   [Quickstart](/v0.1/docs/modules/model_io/quick_start/)
        *   [Concepts](/v0.1/docs/modules/model_io/concepts/)
        *   [Prompts](/v0.1/docs/modules/model_io/prompts/)
            
        *   [LLMs](/v0.1/docs/modules/model_io/llms/)
            
        *   [Chat Models](/v0.1/docs/modules/model_io/chat/)
            
        *   [Model I/O](/v0.1/docs/modules/model_io/)
        *   [Output Parsers](/v0.1/docs/modules/model_io/output_parsers/)
            
    *   [Retrieval](/v0.1/docs/modules/data_connection/)
        
    *   [Chains](/v0.1/docs/modules/chains/)
    *   [Agents](/v0.1/docs/modules/agents/)
        
    *   [More](/v0.1/docs/modules/memory/)
        
*   [Security](/v0.1/docs/security/)
*   [Guides](/v0.1/docs/guides/)
    
*   [Ecosystem](/v0.1/docs/ecosystem/)
    
*   [LangGraph](/v0.1/docs/langgraph/)
*   * * *
    

*   [](/v0.1/)
*   [Modules](/v0.1/docs/modules/)
*   [Model I/O](/v0.1/docs/modules/model_io/)
*   Concepts

On this page

Concepts
========

The core element of any language model application is... the model. LangChain gives you the building blocks to interface with any language model. Everything in this section is about making it easier to work with models. This largely involves a clear interface for what a model is, helper utils for constructing inputs to models, and helper utils for working with the outputs of models.

Models[​](#models "Direct link to Models")
------------------------------------------

There are two main types of models that LangChain integrates with: LLMs and Chat Models. These are defined by their input and output types.

### LLMs[​](#llms "Direct link to LLMs")

LLMs in LangChain refer to pure text completion models. The APIs they wrap take a string prompt as input and output a string completion. OpenAI's GPT-3 is implemented as an LLM.

### Chat Models[​](#chat-models "Direct link to Chat Models")

Chat models are often backed by LLMs but tuned specifically for having conversations. Crucially, their provider APIs use a different interface than pure text completion models. Instead of a single string, they take a list of chat messages as input and they return an AI message as output. See the section below for more details on what exactly a message consists of. GPT-4 and Anthropic's Claude-2 are both implemented as chat models.

### Considerations[​](#considerations "Direct link to Considerations")

These two API types have pretty different input and output schemas. This means that the best way to interact with them may be quite different. Although LangChain makes it possible to treat them interchangeably, that doesn't mean you **should**. In particular, the prompting strategies for LLMs vs ChatModels may be quite different. This means that you will want to make sure the prompt you are using is designed for the model type you are working with.

Additionally, not all models are the same. Different models have different prompting strategies that work best for them. For example, Anthropic's models work best with XML while OpenAI's work best with JSON. This means that the prompt you use for one model may not transfer to other ones. LangChain provides a lot of default prompts, however, these are not guaranteed to work well with the model are you using. Historically speaking, most prompts work well with OpenAI but are not heavily tested on other models. This is something we are working to address, but it is something you should keep in mind.

Messages[​](#messages "Direct link to Messages")
------------------------------------------------

ChatModels take a list of messages as input and return a message. There are a few different types of messages. All messages have a `role` and a `content` property. The `role` describes WHO is saying the message. LangChain has different message classes for different roles. The `content` property describes the content of the message. This can be a few different things:

*   A string (most models are this way)
*   A List of dictionaries (this is used for multi-modal input, where the dictionary contains information about that input type and that input location)

In addition, messages have an `additional_kwargs` property. This is where additional information about messages can be passed. This is largely used for input parameters that are _provider specific_ and not general. The best-known example of this is `function_call` from OpenAI.

### HumanMessage[​](#humanmessage "Direct link to HumanMessage")

This represents a message from the user. Generally consists only of content.

### AIMessage[​](#aimessage "Direct link to AIMessage")

This represents a message from the model. This may have `additional_kwargs` in it - for example, `function_call` if using OpenAI Function calling.

### SystemMessage[​](#systemmessage "Direct link to SystemMessage")

This represents a system message. Only some models support this. This tells the model how to behave. This generally only consists of content.

### FunctionMessage[​](#functionmessage "Direct link to FunctionMessage")

This represents the result of a function call. In addition to `role` and `content`, this message has a `name` parameter which conveys the name of the function that was called to produce this result.

### ToolMessage[​](#toolmessage "Direct link to ToolMessage")

This represents the result of a tool call. This is distinct from a FunctionMessage to match OpenAI's `function` and `tool` message types. In addition to `role` and `content`, this message has a `tool_call_id` parameter which conveys the id of the call to the tool that was called to produce this result.

Prompts[​](#prompts "Direct link to Prompts")
---------------------------------------------

The inputs to language models are often called prompts. Oftentimes, the user input from your app is not the direct input to the model. Rather, their input is transformed in some way to produce the string or list of messages that go into the model. The objects that take user input and transform it into the final string or messages are known as "Prompt Templates". LangChain provides several abstractions to make working with prompts easier.

### PromptValue[​](#promptvalue "Direct link to PromptValue")

ChatModels and LLMs take different input types. PromptValue is a class designed to be interoperable between the two. It exposes a method to be cast to a string (to work with LLMs) and another to be cast to a list of messages (to work with ChatModels).

### PromptTemplate[​](#prompttemplate "Direct link to PromptTemplate")

This is an example of a prompt template. This consists of a template string. This string is then formatted with user inputs to produce a final string.

### MessagePromptTemplate[​](#messageprompttemplate "Direct link to MessagePromptTemplate")

This is an example of a prompt template. This consists of a template **message** - meaning a specific role and a PromptTemplate. This PromptTemplate is then formatted with user inputs to produce a final string that becomes the `content` of this message.

#### HumanMessagePromptTemplate[​](#humanmessageprompttemplate "Direct link to HumanMessagePromptTemplate")

This is MessagePromptTemplate that produces a HumanMessage.

#### AIMessagePromptTemplate[​](#aimessageprompttemplate "Direct link to AIMessagePromptTemplate")

This is MessagePromptTemplate which produces an AIMessage.

#### SystemMessagePromptTemplate[​](#systemmessageprompttemplate "Direct link to SystemMessagePromptTemplate")

This is MessagePromptTemplate that produces a SystemMessage.

### MessagesPlaceholder[​](#messagesplaceholder "Direct link to MessagesPlaceholder")

Oftentimes inputs to prompts can be a list of messages. This is when you would use a MessagesPlaceholder. These objects are parameterized by a `variable_name` argument. The input with the same value as this `variable_name` value should be a list of messages.

### ChatPromptTemplate[​](#chatprompttemplate "Direct link to ChatPromptTemplate")

This is an example of a prompt template. This consists of a list of MessagePromptTemplates or MessagePlaceholders. These are then formatted with user inputs to produce a final list of messages.

Output Parsers[​](#output-parsers "Direct link to Output Parsers")
------------------------------------------------------------------

The output of models is either strings or a message. Oftentimes, the string or messages contain information formatted in a specific format to be used downstream (e.g. a comma-separated list, or JSON blob). Output parsers are responsible for taking in the output of a model and transforming it into a more usable form. These generally work on the `content` of the output message but occasionally work on values in the `additional_kwargs` field.

### StrOutputParser[​](#stroutputparser "Direct link to StrOutputParser")

This is a simple output parser that just converts the output of a language model (LLM or ChatModel) into a string. If the model is an LLM (and therefore outputs a string) it just passes that string through. If the output is a ChatModel (and therefore outputs a message) it passes through the `.content` attribute of the message.

### OpenAI Functions Parsers[​](#openai-functions-parsers "Direct link to OpenAI Functions Parsers")

There are a few parsers dedicated to working with OpenAI function calling. They take the output of the `function_call` and `arguments` parameters (which are inside `additional_kwargs`) and work with those, largely ignoring content.

### Agent Output Parsers[​](#agent-output-parsers "Direct link to Agent Output Parsers")

[Agents](/v0.1/docs/modules/agents/) are systems that use language models to determine what steps to take. The output of a language model therefore needs to be parsed into some schema that can represent what actions (if any) are to be taken. AgentOutputParsers are responsible for taking raw LLM or ChatModel output and converting it to that schema. The logic inside these output parsers can differ depending on the model and prompting strategy being used.

* * *

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

[

Previous

Quickstart

](/v0.1/docs/modules/model_io/quick_start/)[

Next

Prompts

](/v0.1/docs/modules/model_io/prompts/)

*   [Models](#models)
    *   [LLMs](#llms)
    *   [Chat Models](#chat-models)
    *   [Considerations](#considerations)
*   [Messages](#messages)
    *   [HumanMessage](#humanmessage)
    *   [AIMessage](#aimessage)
    *   [SystemMessage](#systemmessage)
    *   [FunctionMessage](#functionmessage)
    *   [ToolMessage](#toolmessage)
*   [Prompts](#prompts)
    *   [PromptValue](#promptvalue)
    *   [PromptTemplate](#prompttemplate)
    *   [MessagePromptTemplate](#messageprompttemplate)
    *   [MessagesPlaceholder](#messagesplaceholder)
    *   [ChatPromptTemplate](#chatprompttemplate)
*   [Output Parsers](#output-parsers)
    *   [StrOutputParser](#stroutputparser)
    *   [OpenAI Functions Parsers](#openai-functions-parsers)
    *   [Agent Output Parsers](#agent-output-parsers)

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.