Structured Output Parser dynamic

in the structured, how can dynamic number of the item?

i am using gpt-oss-20b, but if i have 3 item, it also output 2 item instead.

{
“item_0_description”: “Computer CPU”,
“item_0_quantity”: 6,
“item_0_cost”: 15,
“item_0_amount”: 90,
“item_1_description”: “Chair Wooden”,
“item_1_quantity”: 8,
“item_1_cost”: 10,
“item_1_amount”: 80,
}

Hi @KennethYCK

I recommend setting “Schema Type” to JSON Schema instead,


You can ask any AI to generate one from your example data:

{
  "type": "object",
  "properties": {
    "items": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "description": {
            "type": "string"
          },
          "quantity": {
            "type": "integer"
          },
          "cost": {
            "type": "number"
          },
          "amount": {
            "type": "number"
          }
        },
        "required": ["description", "quantity", "cost", "amount"]
      }
    }
  }
}

This array-based structure will handle dynamic numbers of items much better than the flat indexed format.

1 Like

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