fix(components): normalize ConditionAgent response content before parsing#6072
Open
jslim-23 wants to merge 2 commits intoFlowiseAI:mainfrom
Open
fix(components): normalize ConditionAgent response content before parsing#6072jslim-23 wants to merge 2 commits intoFlowiseAI:mainfrom
jslim-23 wants to merge 2 commits intoFlowiseAI:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors the ConditionAgent to extract the LLM response content into a single variable, responseContent, which is then reused for analytics, JSON parsing, and the final output. This change improves consistency and reduces redundant processing. A suggestion was provided to truncate the raw response content in error logs to enhance readability when parsing fails.
| `Failed to parse a valid scenario from the LLM's response. Please check if the model is capable of following JSON output instructions. Raw LLM Response: "${ | ||
| response.content as string | ||
| }"` | ||
| `Failed to parse a valid scenario from the LLM's response. Please check if the model is capable of following JSON output instructions. Raw LLM Response: "${responseContent}"` |
Contributor
There was a problem hiding this comment.
For better readability in error logs, it's a good practice to truncate long raw responses. The responseContent could be quite large, making the error message difficult to read. Consider truncating it if it exceeds a certain length, similar to how it's done in parseJsonBody.
Suggested change
| `Failed to parse a valid scenario from the LLM's response. Please check if the model is capable of following JSON output instructions. Raw LLM Response: "${responseContent}"` | |
| "Failed to parse a valid scenario from the LLM's response. Please check if the model is capable of following JSON output instructions. Raw LLM Response: \"" + responseContent.substring(0, 200) + (responseContent.length > 200 ? "..." : "") + "\"" |
References
- Prioritize code readability and understandability over conciseness. Truncating large blobs in logs improves the readability and utility of error messages for debugging.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ConditionAgent currently assumes
response.contentis always a string when parsing the model output. In LangChain v1,response.contentmay also be returned as(ContentBlock | ContentBlock.Text)[], which can cause JSON parsing to fail inConditionAgent.This change normalizes the response content before parsing by reusing the existing
extractResponseContent()helper, keeping response handling consistent with other parts of the codebase.The parse error path is also updated to report the same normalized content instead of casting
response.contentto string again in the catch block.Changes
Use
extractResponseContent(response)before callingparseJsonMarkdown()inpackages/components/nodes/agentflow/ConditionAgent/ConditionAgent.tsReuse the normalized response content in analytics, parsing, output content, and parse error reporting
How to reproduce the bug
response.contentas text content blocks