Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookPrompt + LLMRAGMultiple chainsQuerying a SQL DBAgentsCode writingAdding memoryAdding moderationUsing toolsLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsMemoryAgentsCallbacksModulesSecurityGuidesMoreLangChain Expression LanguageCookbookPrompt + LLMOn this pagePrompt + LLMThe most common and valuable composition is taking:PromptTemplate / ChatPromptTemplate -> LLM / ChatModel -> OutputParserAlmost any other chains you build will use this building block.PromptTemplate + LLM‚ÄãThe simplest composition is just combing a prompt and model to create a chain that takes user input, adds it to a prompt, passes it to a model, and returns the raw model input.Note, you can mix and match PromptTemplate/ChatPromptTemplates and LLMs/ChatModels as you like here.from langchain.prompts import ChatPromptTemplatefrom langchain.chat_models import ChatOpenAIprompt = ChatPromptTemplate.from_template("tell me a joke about {foo}")model = ChatOpenAI()chain = prompt | modelchain.invoke({"foo": "bears"})    AIMessage(content="Why don't bears wear shoes?\n\nBecause they have bear feet!", additional_kwargs={}, example=False)Often times we want to attach kwargs that'll be passed to each model call. Here's a few examples of that:Attaching Stop Sequences‚Äãchain = prompt | model.bind(stop=["\n"])chain.invoke({"foo": "bears"})    AIMessage(content='Why did the bear never wear shoes?', additional_kwargs={}, example=False)Attaching Function Call information‚Äãfunctions = [    {      "name": "joke",      "description": "A joke",      "parameters": {        "type": "object",        "properties": {          "setup": {            "type": "string",            "description": "The setup for the joke"          },          "punchline": {            "type":
The most common and valuable composition is taking:
The most common and valuable composition is taking: ->: Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookPrompt + LLMRAGMultiple chainsQuerying a SQL DBAgentsCode writingAdding memoryAdding moderationUsing toolsLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsMemoryAgentsCallbacksModulesSecurityGuidesMoreLangChain Expression LanguageCookbookPrompt + LLMOn this pagePrompt + LLMThe most common and valuable composition is taking:PromptTemplate / ChatPromptTemplate -> LLM / ChatModel -> OutputParserAlmost any other chains you build will use this building block.PromptTemplate + LLM‚ÄãThe simplest composition is just combing a prompt and model to create a chain that takes user input, adds it to a prompt, passes it to a model, and returns the raw model input.Note, you can mix and match PromptTemplate/ChatPromptTemplates and LLMs/ChatModels as you like here.from langchain.prompts import ChatPromptTemplatefrom langchain.chat_models import ChatOpenAIprompt = ChatPromptTemplate.from_template("tell me a joke about {foo}")model = ChatOpenAI()chain = prompt | modelchain.invoke({"foo": "bears"})    AIMessage(content="Why don't bears wear shoes?\n\nBecause they have bear feet!", additional_kwargs={}, example=False)Often times we want to attach kwargs that'll be passed to each model call. Here's a few examples of that:Attaching Stop Sequences‚Äãchain = prompt | model.bind(stop=["\n"])chain.invoke({"foo": "bears"})    AIMessage(content='Why did the bear never wear shoes?', additional_kwargs={}, example=False)Attaching Function Call information‚Äãfunctions = [    {      "name": "joke",      "description": "A joke",      "parameters": {        "type": "object",        "properties": {          "setup": {            "type": "string",            "description": "The setup for the joke"          },          "punchline": {            "type":