There's a bug in structured output parser on [email protected]

Hi,
There is a bug in the structured output parser. Even a basic example will outline this.

I simply connected the structured output (with the default JSON schema) to a AI Agent block and ran the text ‘What is the best place to buy properties?’ and it dies in error.

Upon closer investigation it seems Open AI has passed the correct response back and in the correct format. But n8n doesn’t recognise it and it sends it back to OpenAI to redo.

The AI is actually so smart that it simply removes the structured output format and goes back to the original JSON of action / action_input.

What is the error message (if any)?

ERROR: Failed to parse. Text: “The best place to buy properties can vary widely depending on various factors. However, an example of a potentially good place to buy could be California, more specifically cities like Los Angeles, San Francisco, and San Diego.”. Error: Error: Failed to parse. Text: “The best place to buy properties can vary widely depending on various factors. However, an example of a potentially good place to buy could be California, more specifically cities like Los Angeles, San Francisco, and San Diego.”. Error: SyntaxError: Unexpected token T in JSON at position 0

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version: [email protected]
  • Database (default: SQLite): cloud
  • n8n EXECUTIONS_PROCESS setting (default: own, main): cloud
  • Running n8n via (Docker, npm, n8n cloud, desktop app): cloud
  • Operating system: cloud

Note: Tried this on 1.34 and also doesn’t work right.

On further inspection and running it several times and it did work once when the AI generated the following format -

{
“action”: “Final Answer”,
“action_input”: “{"output": {"state": "New York", "cities": ["New York City", "Buffalo", "Rochester", "Yonkers", "Syracuse"]}}”
}

So in order for this to work the AI must output the answer with the ‘action’ and the ‘action_input’ fields. However, the description given to the AI is poor to describe this and its not possible to add JSON examples in the ‘human message’ input field (as it dies whenever it sees a ‘}’ bracket)

please make the description field fully editable including the instructions for formatting.

2 Likes

Hi @Sow_B! My apologies that it’s taken so long for you to get a response here. I was able to reproduce this issue so I’ve ticketed it and shared it with our engineering team. We’ll keep you updated on any fix deployed to resolve this issue. Thanks for being a part of the community and sharing things like this so we can fix them!

1 Like