-
Notifications
You must be signed in to change notification settings - Fork 15.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ValueError: Missing some input keys: - passed data requires input keys if containing { } #13055
Comments
🤖 Hello @Kaotic3, I'm here to help! I'm an AI bot dedicated to assisting with issues related to LangChain. I can help you debug issues, answer your questions, and guide you on how to become a better contributor. While we wait for a human maintainer, let's see if we can tackle this issue together. I'm analyzing your problem now and will get back to you with a more detailed response soon. |
🤖 Based on the information you've provided and the context of similar issues in the LangChain repository, it seems that the issue you're experiencing is related to how Python's built-in string formatting mechanism works. When you use curly braces In your case, the document content you're passing to the There are a few potential solutions to this issue:
document_content = "...1 2 ------------------------------------ {{w14 w15 w16se w16cid w16 w16cex w16sdtdh wp14}}{{DP}}{{AD}}{{S::}}" By doubling the curly braces, you're instructing Python to treat them as literal characters in the string, rather than as placeholders for variables.
prompt_template = FewShotPromptTemplate(
examples = examples,
example_prompt = get_prompt_template(example_template, example_variables),
prefix = prefix,
suffix = suffix,
input_variables = input_variables,
template_format = 'jinja2'
)
I hope this helps! If you have any further questions or if the issue persists, please let me know. Sources
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Thanks jinja2 worked perfectly. |
I got the same problem, there are many "{x}..{xx}" in my system prompt, how can I handle this? |
System Info
Python 3.11.5
Langchain (pip show) 0.0.327
Windows OS
Visual Studio Code
Who can help?
@eyurtsev
Information
Related Components
Reproduction
I searched and was surprised this has not come up.
I am using LangChain for a RAG workflow - and when I send a document, if that document contains { } - it throws a missing key error - it is treating the content of the document, as it would a normal prompt where you might have "question {question}" and expect an input key of 'question' it then reports back that all of the { } are in fact different missing keys.
For example, my data contains this:
"...1 2 ------------------------------------ {w14 w15 w16se w16cid w16 w16cex w16sdtdh wp14}{DP}{AD}{S::}"
It will say that we are missing numerous keys:
ValueError: Missing some input keys: {'AD', 'w14 w15 w16se w16cid w16 w16cex w16sdtdh wp14', ...}
Now, I can clean the data prior to sending, but I was wondering whether it should behave like this given that this document is already within { } as content?
I use the "FewShotPromptTemplate" to create a prompt which includes a "Suffix" and my suffix is:
Here content is the content of the document that contains the { } set out above.
I build the prompt like this:
I also did a test using another piece of code:
Introducing a random {AD} into the text response. It did not fail. It messed up the results, but it didn't actually cause any missing input key errors.
So this may be limited to the FewShotPromptTemplate?
Expected behavior
I would have thought that anything passed within a curly bracket set would be considered as plain text, not parsed for further keys that might be embedded in that curly bracket set and throw an error when it cannot find them?
Maybe I am wrong, but that is what I would have expected and is what appears to happen when using the ChatPromptTemplate.from_template?
The text was updated successfully, but these errors were encountered: