Skip to content

Commit

Permalink
docs: Adds example to error code page (#7010)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 authored Oct 17, 2024
1 parent 703b001 commit 2f91cf2
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 38 deletions.
74 changes: 37 additions & 37 deletions docs/core_docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -288,16 +288,6 @@ docs/integrations/text_embedding/bedrock.md
docs/integrations/text_embedding/bedrock.mdx
docs/integrations/text_embedding/azure_openai.md
docs/integrations/text_embedding/azure_openai.mdx
docs/integrations/retrievers/tavily.md
docs/integrations/retrievers/tavily.mdx
docs/integrations/retrievers/kendra-retriever.md
docs/integrations/retrievers/kendra-retriever.mdx
docs/integrations/retrievers/exa.md
docs/integrations/retrievers/exa.mdx
docs/integrations/retrievers/bm25.md
docs/integrations/retrievers/bm25.mdx
docs/integrations/retrievers/bedrock-knowledge-bases.md
docs/integrations/retrievers/bedrock-knowledge-bases.mdx
docs/integrations/llms/together.md
docs/integrations/llms/together.mdx
docs/integrations/llms/openai.md
Expand All @@ -320,6 +310,32 @@ docs/integrations/llms/azure.md
docs/integrations/llms/azure.mdx
docs/integrations/llms/arcjet.md
docs/integrations/llms/arcjet.mdx
docs/integrations/retrievers/tavily.md
docs/integrations/retrievers/tavily.mdx
docs/integrations/retrievers/kendra-retriever.md
docs/integrations/retrievers/kendra-retriever.mdx
docs/integrations/retrievers/exa.md
docs/integrations/retrievers/exa.mdx
docs/integrations/retrievers/bm25.md
docs/integrations/retrievers/bm25.mdx
docs/integrations/retrievers/bedrock-knowledge-bases.md
docs/integrations/retrievers/bedrock-knowledge-bases.mdx
docs/integrations/retrievers/self_query/weaviate.md
docs/integrations/retrievers/self_query/weaviate.mdx
docs/integrations/retrievers/self_query/vectara.md
docs/integrations/retrievers/self_query/vectara.mdx
docs/integrations/retrievers/self_query/supabase.md
docs/integrations/retrievers/self_query/supabase.mdx
docs/integrations/retrievers/self_query/qdrant.md
docs/integrations/retrievers/self_query/qdrant.mdx
docs/integrations/retrievers/self_query/pinecone.md
docs/integrations/retrievers/self_query/pinecone.mdx
docs/integrations/retrievers/self_query/memory.md
docs/integrations/retrievers/self_query/memory.mdx
docs/integrations/retrievers/self_query/hnswlib.md
docs/integrations/retrievers/self_query/hnswlib.mdx
docs/integrations/retrievers/self_query/chroma.md
docs/integrations/retrievers/self_query/chroma.mdx
docs/integrations/chat/togetherai.md
docs/integrations/chat/togetherai.mdx
docs/integrations/chat/openai.md
Expand Down Expand Up @@ -350,32 +366,6 @@ docs/integrations/chat/arcjet.md
docs/integrations/chat/arcjet.mdx
docs/integrations/chat/anthropic.md
docs/integrations/chat/anthropic.mdx
docs/integrations/retrievers/self_query/weaviate.md
docs/integrations/retrievers/self_query/weaviate.mdx
docs/integrations/retrievers/self_query/vectara.md
docs/integrations/retrievers/self_query/vectara.mdx
docs/integrations/retrievers/self_query/supabase.md
docs/integrations/retrievers/self_query/supabase.mdx
docs/integrations/retrievers/self_query/qdrant.md
docs/integrations/retrievers/self_query/qdrant.mdx
docs/integrations/retrievers/self_query/pinecone.md
docs/integrations/retrievers/self_query/pinecone.mdx
docs/integrations/retrievers/self_query/memory.md
docs/integrations/retrievers/self_query/memory.mdx
docs/integrations/retrievers/self_query/hnswlib.md
docs/integrations/retrievers/self_query/hnswlib.mdx
docs/integrations/retrievers/self_query/chroma.md
docs/integrations/retrievers/self_query/chroma.mdx
docs/integrations/document_loaders/file_loaders/unstructured.md
docs/integrations/document_loaders/file_loaders/unstructured.mdx
docs/integrations/document_loaders/file_loaders/text.md
docs/integrations/document_loaders/file_loaders/text.mdx
docs/integrations/document_loaders/file_loaders/pdf.md
docs/integrations/document_loaders/file_loaders/pdf.mdx
docs/integrations/document_loaders/file_loaders/directory.md
docs/integrations/document_loaders/file_loaders/directory.mdx
docs/integrations/document_loaders/file_loaders/csv.md
docs/integrations/document_loaders/file_loaders/csv.mdx
docs/integrations/document_loaders/web_loaders/web_puppeteer.md
docs/integrations/document_loaders/web_loaders/web_puppeteer.mdx
docs/integrations/document_loaders/web_loaders/web_cheerio.md
Expand All @@ -387,4 +377,14 @@ docs/integrations/document_loaders/web_loaders/pdf.mdx
docs/integrations/document_loaders/web_loaders/langsmith.md
docs/integrations/document_loaders/web_loaders/langsmith.mdx
docs/integrations/document_loaders/web_loaders/firecrawl.md
docs/integrations/document_loaders/web_loaders/firecrawl.mdx
docs/integrations/document_loaders/web_loaders/firecrawl.mdx
docs/integrations/document_loaders/file_loaders/unstructured.md
docs/integrations/document_loaders/file_loaders/unstructured.mdx
docs/integrations/document_loaders/file_loaders/text.md
docs/integrations/document_loaders/file_loaders/text.mdx
docs/integrations/document_loaders/file_loaders/pdf.md
docs/integrations/document_loaders/file_loaders/pdf.mdx
docs/integrations/document_loaders/file_loaders/directory.md
docs/integrations/document_loaders/file_loaders/directory.mdx
docs/integrations/document_loaders/file_loaders/csv.md
docs/integrations/document_loaders/file_loaders/csv.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,55 @@

A [prompt template](/docs/concepts#prompt-templates) received missing or invalid input variables.

One unexpected way this can occur is if you add a JSON object directly into a prompt template:

```ts
import { PromptTemplate } from "@langchain/core/prompts";
import { ChatOpenAI } from "@langchain/openai";

const prompt = PromptTemplate.fromTemplate(`You are a helpful assistant.
Here is an example of how you should respond:
{
"firstName": "John",
"lastName": "Doe",
"age": 21
}
Now, answer the following question:
{question}`);
```

You might think that the above prompt template should require a single input key named `question`, but the JSON object will be
interpreted as an additional variable because the curly braces (`{`) are not escaped, and should be preceded by a second brace instead, like this:

```ts
import { PromptTemplate } from "@langchain/core/prompts";
import { ChatOpenAI } from "@langchain/openai";

const prompt = PromptTemplate.fromTemplate(`You are a helpful assistant.
Here is an example of how you should respond:
{{
"firstName": "John",
"lastName": "Doe",
"age": 21
}}
Now, answer the following question:
{question}`);
```

## Troubleshooting

The following may help resolve this error:

- Double-check your prompt template to ensure that it is correct.
- If you are using the default format and you are using curly braces `{` anywhere in your template, they should be double escaped like this: `{{`.
- If you are using default formatting and you are using curly braces `{` anywhere in your template, they should be double escaped like this: `{{`, as shown above.
- If you are using a [`MessagesPlaceholder`](/docs/concepts/#messagesplaceholder), make sure that you are passing in an array of messages or message-like objects.
- If you are using shorthand tuples to declare your prompt template, make sure that the variable name is wrapped in curly braces (`["placeholder", "{messages}"]`).
- Try viewing the inputs into your prompt template using [LangSmith](https://docs.smith.langchain.com/) or log statements to confirm they appear as expected.
Expand Down

0 comments on commit 2f91cf2

Please sign in to comment.