-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Fix: Tool action_input
containing markdown with JSON
#1203
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
… JSON and then attempt to find JSON in text
26688d5
to
fece0e3
Compare
action_input
containing markdown with JSON
let action_input: string | undefined; | ||
|
||
try { | ||
({ action, action_input } = JSON.parse(trimmedText)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The agent is prompted to return JSON in a markdown block, so we're actually being optimistic for an invalid response here?
My gut says we should try to improve the prompt to more strictly output markdown - can you give an end-to-end example of an input that caused this? |
Fair. It should be noted I'm new to Here's a brief description of what I'm doing without going into too many details since the details are confidential to work at Shopify.
Here's a snippet of the verbose output modified to match the
|
If you don't explicitly specify that the tool returns JSON output does it help? If you're looking for the overall output of the agent to be in a different format, an output or output fixing parser may be helpful: https://js.langchain.com/docs/modules/prompts/output_parsers/ Output parsers contain a prompt that nudges the chain to return a specific format, and output fixing parsers will attempt to fix the output of a given run by passing mismatched output into another LLM. |
I actually don't explicitly specify I'm returning JSON. I just return the JSON as string. I don't include the any markdown declarations that would specify the returned value is JSON. I just return The agent wraps my code with the markdown specifier and then when the Final Answer is parsed it fails. I'll take a look at Output parsers to understand how they could be helpful. |
Ah gotcha - an output fixing parser may help you yeah. But I think one or two prompt tweaks may fix it in a more sustainable way - I can give it a shot later today. If you can share a full code sample that consistently repros this it would speed me up significantly? |
Hey @mikkoh and @HenryHengZJ I opened #1292 to address this with some prompt tweaks and a retry mechanism for poorly formatted agent action outputs - have a look at that one and I'll close this if it looks reasonable to you! |
Do we have the retry mechanism there? So far I don't see the error anymore, think the prompt and output parser kinda fixed it |
Yes, though it's not merged and released yet. Great to hear that! |
#1292 was merged last week - if this recurs please open an issue. |
This PR fixes a bug where if a
Tool
returns JSON markdown in theaction_input
string thenChatConversationalAgentOutputParser.parse
fails to parse theaction_input
properly.An example
text
/message that fails to parse:This PR optimistically tries to parse the
text
/message as JSON and if that fails then it attempts to find the JSON in the string.Before this PR the above example fails with:
This PR also adds further error handling to return that either
action
oraction_input
could not be found.