Why is the LLM generating malformed JSON?
A common cause is that the prompt doesn't clearly constrain the expected output format, allowing the model to produce responses that don't match the required JSON schema. To diagnose and resolve the issue, follow these steps:
- Go to AI Agent Studio and open the
Workflows
tab. - Select Edit
to modify a workflow. - From the toolbar, select Debug
. - Enter a prompt in Ask Oracle and submit it to run the workflow.
- Inspect the output generated by the LLM node.
- Compare the generated output with the schema expected by the downstream node.
- If applicable, update the LLM node's output specification.
- Add or refine output-format instructions using a configuration override (for
example, explicitly specify the required JSON structure).Note: Clearly define the expected JSON structure in your prompt, including all required fields, their data types, and any formatting requirements. Providing a precise and well-defined output specification helps the LLM generate valid and consistent JSON more reliably.
- Step into the downstream node.
- Verify that the downstream node successfully accepts the corrected JSON output.