Structured output parser issue

Hello,

I am having an issue with the Structured Output Parser.
I am getting the following error randomly:
ERROR: Failed to parse. Text: “{“id”: 1, “sentiment”: “neutral”}”. Error: [ { “code”: “invalid_type”, “expected”: “array”, “received”: “object”, “path”: , “message”: “Expected array, received object” } ]

This is my json schema:

{
  "type": "object",
  "properties": {
    "id": {
      "type": "number"
    },
    "sentiment": {
      "type": "string"
    }
  }
}

1 out of 3 times the workflow just passes and no error is rased.

Hi @Boris_Idesman,

I belive this should be fixed with the latest version of the ai-beta image. Can you try updating and re-try?

If you’re using n8n Cloud just restarting your instance should do the trick. For self-hosted(Docker) you’d need to pull the latest ai-beta image to get the changes.

2 Likes

Self hosted and now I get another error:
ERROR: Failed to parse. Text: “{”__structured__output": {“__structured__output__object”: {“id”: null, “sentiment”: “negative”}, “__structured__output__array”: []}}“. Error: Error: Failed to parse. Text: “{”__structured__output”: {“__structured__output__object”: {“id”: null, “sentiment”: “negative”}, “__structured__output__array”: []}}". Error: [ { “code”: “invalid_type”, “expected”: “number”, “received”: “null”, “path”: [ “__structured__output”, “__structured__output__object”, “id” ], “message”: “Expected number, received null” } ]

@Boris_Idesman This is because model returned null for id. But in your schema you define it as number hence the failed validation. You can either allow null as valid type in your schema(type = ['number', 'null']) or prompt the LM to never return null for id field.

1 Like

I think now it works - thanks for the help. FYI sometimes the workflow with Structured Output Parser just hangs, after a few items being processed.

It failed again but it’s really random.
My schema is:

{
  "type": "object",
  "properties": {
    "id": {
      "type": ["number", null]
    },
    "sentiment": {
      "type": "string"
    }
  }
}

and the error is:
ERROR: Failed to parse. Text: “{”__structured__output":{“__structured__output__object”:{},“__structured__output__array”:[]}}“. Error: Error: Failed to parse. Text: “{”__structured__output”:{“__structured__output__object”:{},“__structured__output__array”:[]}}". Error: [ { “code”: “custom”, “message”: “One and only one of __structured__output__object and __structured__output__array should be present.”, “path”: [ “__structured__output”, “__structured__output” ] } ]

@Boris_Idesman What model and settings are you using? Would be helpful if you could share anonnymized inputs/outputs maybe via DMs.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.