Structure Output Parser fails randomly

Describe the problem/error/question

I have a Basic LLM Chain with a structured output parser. I want to create two personas in an array. I have connected a structured output parser with a json schema.

Every 2 or 3 times i get an error because the actual array is prepended with { “__structured__output”: { “__structured__output__array”:

The other times i get only the array which than can be parsed correctly.

What is the error message (if any)?

Failed to parse. Text: "```json { "__structured__output": { "__structured__output__array": [ { "name": "Julia Müller", "demographic_characteristics": { "age": 42, "gender": "weiblich", "occupation": "IT-Abteilungsleitung", "education_level": ...

Share the output returned by the last node

see error message

Schema

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "name": { "type": "string" },
      "demographic_characteristics": {
        "type": "object",
        "properties": {
          "age": { "type": "integer" },
          "gender": { "type": "string" },
          "occupation": { "type": "string" },
          "education_level": { "type": "string" }
        },
        "required": ["age", "gender", "occupation", "education_level"]
      },
      "psychographic_characteristics": {
        "type": "object",
        "properties": {
          "interests": { "type": "array", "items": { "type": "string" } },
          "hobbies": { "type": "array", "items": { "type": "string" } },
          "values": { "type": "array", "items": { "type": "string" } },
          "lifestyle": { "type": "string" }
        },
        "required": ["interests", "hobbies", "values", "lifestyle"]
      },
      "professional_background": {
        "type": "object",
        "properties": {
          "position": { "type": "string" },
          "industry": { "type": "string" },
          "career_goals": { "type": "string" }
        },
        "required": ["position", "industry", "career_goals"]
      },
      "buying_behavior": {
        "type": "object",
        "properties": {
          "shopping_preferences": { "type": "array", "items": { "type": "string" } },
          "decision_factors": { "type": "array", "items": { "type": "string" } },
          "media_usage": { "type": "string" }
        },
        "required": ["shopping_preferences", "decision_factors", "media_usage"]
      },
      "goals_and_challenges": {
        "type": "object",
        "properties": {
          "personal_goals": { "type": "string" },
          "challenges": { "type": "string" },
          "product_solution": { "type": "string" }
        },
        "required": ["personal_goals", "challenges", "product_solution"]
      },
      "image_description": { "type": "string" }
    },
    "required": [
      "name",
      "demographic_characteristics",
      "psychographic_characteristics",
      "professional_background",
      "buying_behavior",
      "goals_and_challenges",
      "image_description"
    ]
  }
}

Information on your n8n setup

  • n8n version: 1.30.0
  • Database SQLite
  • n8n EXECUTIONS_PROCESS setting default
  • Running n8n via Docker
  • Operating system: MacOS

It looks like your topic is missing some important information. Could you provide the following if applicable.

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

I got a bit further. The problem seems to be that i want an array with multiple personas as output and adapted the schena. I switched to output a single persona on at a time and the problem is gone.

1 Like

Hey @MehrCurry,

It is good to hear that you managed to resolve the issue you were seeing, I have marked your post as the solution as it may help others in the future.

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