-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
[Bug]: LLMTextCompletionProgram fails with KeyError when prompt contains JSON example data #12390
Comments
Hello @kkarski! 👋 I'm Dosu, a bot here to assist you with bug-fixing, answering questions, and guiding you through contributions while we wait for a human maintainer. I'm diving into your issue regarding the |
This is very hard to fix with python string formatting 😓 I suggest escaping your JSON with double brackets |
To address the Here's a concise guide on how to use the
For example: json_data_with_python_format = '{"name": "{user_name}", "age": {user_age}}'
handlebars_template = convert_to_handlebars(json_data_with_python_format) This approach, leveraging the The You can find the As for updates or newer versions of LlamaIndex that might address this issue directly, I couldn't find specific information in the repository. If you need further assistance or have additional questions, feel free to ask. Sources
|
Bug Description
In order to help the LLM output valid JSON objects, it's often helpful to provide a few JSON examples in addition to the Pydantic schema.
The issue is, if any JSON is present in the prompt_template_str, the first {'property' ... } of the JSON example will be interpreted as a {variable} for the str.format() function when the message is being prepared before invoking the LLM. Since it's not actually a variable to be replaced, none can be provided and the str.format() functions fails with a KeyError.
Version
llama-index==0.10.15
Steps to Reproduce
Place any JSON content in the prompt_template_str before invoking LLMTextCompletionProgram.from_defaults()
Relevant Logs/Tracbacks
No response
The text was updated successfully, but these errors were encountered: