Structured Output. Content sometimes cuts off mid way

I am running a large amount of records through batch api using structured outputs with strict mode.

On some records I get the full request object back on the line of the output file but the content property that has the json string just stops before the end of the json object.

It’s not hitting maximum token limit as I have other larger records that work fine, it seems to fail halfway through outputting json on about 1% of requests.

Welcome @evom
Can you share how your json structure schema looks like?

{
  "description": "A comprehensive schema for assessing various aspects of a business website",
  "name": "WorkspaceFullSiteAssessment",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "Services": {
      "description": "Collection of services offered by the company",
      "name": "Services",
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": false,
      "properties": {
        "ServiceList": {
          "description": "List of individual services",
          "name": "ServiceList",
          "type": "array",
          "items": {
            "description": "Details of a single service",
            "name": "Service",
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "Name": {
                "description": "Name of the service",
                "name": "Name",
                "type": "string"
              },
              "Description": {
                "description": "Description of the service",
                "name": "Description",
                "type": [
                  "string",
                  "null"
                ]
              },
              "Benefits": {
                "description": "List of service benefits",
                "name": "Benefits",
                "type": [
                  "array",
                  "null"
                ],
                "items": {
                  "description": "Individual service benefit",
                  "name": "Benefit",
                  "type": "string"
                }
              },
              "Features": {
                "description": "List of service features",
                "name": "Features",
                "type": [
                  "array",
                  "null"
                ],
                "items": {
                  "description": "Individual service feature",
                  "name": "Feature",
                  "type": "string"
                }
              },
              "Price": {
                "description": "Price of the service",
                "name": "Price",
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "required": [
              "Name",
              "Description",
              "Benefits",
              "Features",
              "Price"
            ]
          }
        }
      },
      "required": [
        "ServiceList"
      ]
    },
    "BuildingLocations": {
      "description": "Collection of building locations",
      "name": "BuildingLocations",
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": false,
      "properties": {
        "LocationList": {
          "description": "List of individual building locations",
          "name": "LocationList",
          "type": "array",
          "items": {
            "description": "Details of a single building location",
            "name": "Location",
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "Name": {
                "description": "Name of the location",
                "name": "Name",
                "type": "string"
              },
              "Description": {
                "description": "Description of the location",
                "name": "Description",
                "type": [
                  "string",
                  "null"
                ]
              },
              "Address": {
                "description": "Address of the location",
                "name": "Address",
                "type": [
                  "string",
                  "null"
                ]
              },
              "Phone": {
                "description": "Phone number of the location",
                "name": "Phone",
                "type": [
                  "string",
                  "null"
                ]
              },
              "Email": {
                "description": "Email address of the location",
                "name": "Email",
                "type": [
                  "string",
                  "null"
                ]
              },
              "MainContactPerson": {
                "description": "Main contact person for the location",
                "name": "MainContactPerson",
                "type": [
                  "string",
                  "null"
                ]
              },
              "Facilities": {
                "description": "List of facilities available at the location",
                "name": "Facilities",
                "type": [
                  "array",
                  "null"
                ],
                "items": {
                  "description": "Individual facility",
                  "name": "Facility",
                  "type": "string"
                }
              },
              "ImageURL": {
                "description": "URL of the location image",
                "name": "ImageURL",
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "required": [
              "Name",
              "Description",
              "Address",
              "Phone",
              "Email",
              "MainContactPerson",
              "Facilities",
              "ImageURL"
            ]
          }
        }
      },
      "required": [
        "LocationList"
      ]
    },
    "MeetingRooms": {
      "description": "Collection of meeting rooms offered by the company for booking",
      "name": "MeetingRooms",
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": false,
      "properties": {
        "RoomList": {
          "description": "List of individual meeting rooms",
          "name": "RoomList",
          "type": "array",
          "items": {
            "description": "Details of a single meeting room",
            "name": "Room",
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "Name": {
                "description": "Name of the meeting room",
                "name": "Name",
                "type": "string"
              },
              "Description": {
                "description": "Description of the meeting room",
                "name": "Description",
                "type": [
                  "string",
                  "null"
                ]
              },
              "Price": {
                "description": "Price of the meeting room",
                "name": "Price",
                "type": [
                  "string",
                  "null"
                ]
              },
              "BillingInterval": {
                "description": "Billing interval for the meeting room",
                "name": "BillingInterval",
                "type": [
                  "string",
                  "null"
                ]
              },
              "Features": {
                "description": "List of meeting room features",
                "name": "Features",
                "type": [
                  "array",
                  "null"
                ],
                "items": {
                  "description": "Individual meeting room feature",
                  "name": "Feature",
                  "type": "string"
                }
              },
              "Addons": {
                "description": "List of meeting room addons",
                "name": "Addons",
                "type": [
                  "array",
                  "null"
                ],
                "items": {
                  "description": "Individual meeting room addon",
                  "name": "Addon",
                  "type": "string"
                }
              },
              "ImageURL": {
                "description": "URL of the meeting room image",
                "name": "ImageURL",
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "required": [
              "Name",
              "Description",
              "Price",
              "BillingInterval",
              "Features",
              "Addons",
              "ImageURL"
            ]
          }
        }
      },
      "required": [
        "RoomList"
      ]
    },
    "Offices": {
      "description": "Collection of offices offered by the company to book or rent",
      "name": "Offices",
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": false,
      "properties": {
        "OfficeList": {
          "description": "List of individual offices",
          "name": "OfficeList",
          "type": "array",
          "items": {
            "description": "Details of a single office",
            "name": "Office",
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "Name": {
                "description": "Name of the office",
                "name": "Name",
                "type": "string"
              },
              "Description": {
                "description": "Description of the office",
                "name": "Description",
                "type": [
                  "string",
                  "null"
                ]
              },
              "Price": {
                "description": "Price of the office",
                "name": "Price",
                "type": [
                  "string",
                  "null"
                ]
              },
              "BillingInterval": {
                "description": "Billing interval for the office",
                "name": "BillingInterval",
                "type": [
                  "string",
                  "null"
                ]
              },
              "Features": {
                "description": "List of office features",
                "name": "Features",
                "type": [
                  "array",
                  "null"
                ],
                "items": {
                  "description": "Individual office feature",
                  "name": "Feature",
                  "type": "string"
                }
              },
              "Addons": {
                "description": "List of office addons",
                "name": "Addons",
                "type": [
                  "array",
                  "null"
                ],
                "items": {
                  "description": "Individual office addon",
                  "name": "Addon",
                  "type": "string"
                }
              },
              "ImageURL": {
                "description": "URL of the office image",
                "name": "ImageURL",
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "required": [
              "Name",
              "Description",
              "Price",
              "BillingInterval",
              "Features",
              "Addons",
              "ImageURL"
            ]
          }
        }
      },
      "required": [
        "OfficeList"
      ]
    },
    "Desks": {
      "description": "Collection of desk usage offers that can be purchased from the company",
      "name": "Desks",
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": false,
      "properties": {
        "DeskList": {
          "description": "List of individual desks",
          "name": "DeskList",
          "type": "array",
          "items": {
            "description": "Details of a single desk",
            "name": "Desk",
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "Name": {
                "description": "Name of the desk",
                "name": "Name",
                "type": "string"
              },
              "Description": {
                "description": "Description of the desk",
                "name": "Description",
                "type": [
                  "string",
                  "null"
                ]
              },
              "Price": {
                "description": "Price of the desk",
                "name": "Price",
                "type": [
                  "string",
                  "null"
                ]
              },
              "BillingInterval": {
                "description": "Billing interval for the desk",
                "name": "BillingInterval",
                "type": [
                  "string",
                  "null"
                ]
              },
              "Features": {
                "description": "List of desk features",
                "name": "Features",
                "type": [
                  "array",
                  "null"
                ],
                "items": {
                  "description": "Individual desk feature",
                  "name": "Feature",
                  "type": "string"
                }
              },
              "Addons": {
                "description": "List of desk addons",
                "name": "Addons",
                "type": [
                  "array",
                  "null"
                ],
                "items": {
                  "description": "Individual desk addon",
                  "name": "Addon",
                  "type": "string"
                }
              },
              "ImageURL": {
                "description": "URL of the desk image",
                "name": "ImageURL",
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "required": [
              "Name",
              "Description",
              "Price",
              "BillingInterval",
              "Features",
              "Addons",
              "ImageURL"
            ]
          }
        }
      },
      "required": [
        "DeskList"
      ]
    },
    "Memberships": {
      "description": "Collection of memberships offered by the company",
      "name": "Memberships",
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": false,
      "properties": {
        "MembershipList": {
          "description": "List of individual memberships",
          "name": "MembershipList",
          "type": "array",
          "items": {
            "description": "Details of a single membership",
            "name": "Membership",
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "Name": {
                "description": "Name of the membership",
                "name": "Name",
                "type": "string"
              },
              "Description": {
                "description": "Description of the membership",
                "name": "Description",
                "type": [
                  "string",
                  "null"
                ]
              },
              "Price": {
                "description": "Price of the membership",
                "name": "Price",
                "type": [
                  "string",
                  "null"
                ]
              },
              "BillingInterval": {
                "description": "Billing interval for the membership",
                "name": "BillingInterval",
                "type": [
                  "string",
                  "null"
                ]
              },
              "Features": {
                "description": "List of membership features",
                "name": "Features",
                "type": [
                  "array",
                  "null"
                ],
                "items": {
                  "description": "Individual membership feature",
                  "name": "Feature",
                  "type": "string"
                }
              },
              "Addons": {
                "description": "List of membership addons",
                "name": "Addons",
                "type": [
                  "array",
                  "null"
                ],
                "items": {
                  "description": "Individual membership addon",
                  "name": "Addon",
                  "type": "string"
                }
              },
              "ImageURL": {
                "description": "URL of the membership image",
                "name": "ImageURL",
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "required": [
              "Name",
              "Description",
              "Price",
              "BillingInterval",
              "Features",
              "Addons",
              "ImageURL"
            ]
          }
        }
      },
      "required": [
        "MembershipList"
      ]
    },
    "VirtualServices": {
      "description": "Collection of virtual services offered by the company",
      "name": "VirtualServices",
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": false,
      "properties": {
        "VirtualServiceList": {
          "description": "List of individual virtual services",
          "name": "VirtualServiceList",
          "type": "array",
          "items": {
            "description": "Details of a single virtual service",
            "name": "VirtualService",
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "Name": {
                "description": "Name of the virtual service",
                "name": "Name",
                "type": "string"
              },
              "Description": {
                "description": "Description of the virtual service",
                "name": "Description",
                "type": [
                  "string",
                  "null"
                ]
              },
              "Price": {
                "description": "Price of the virtual service",
                "name": "Price",
                "type": [
                  "string",
                  "null"
                ]
              },
              "BillingInterval": {
                "description": "Billing interval for the virtual service",
                "name": "BillingInterval",
                "type": [
                  "string",
                  "null"
                ]
              },
              "Features": {
                "description": "List of virtual service features",
                "name": "Features",
                "type": [
                  "array",
                  "null"
                ],
                "items": {
                  "description": "Individual virtual service feature",
                  "name": "Feature",
                  "type": "string"
                }
              },
              "Addons": {
                "description": "List of virtual service addons",
                "name": "Addons",
                "type": [
                  "array",
                  "null"
                ],
                "items": {
                  "description": "Individual virtual service addon",
                  "name": "Addon",
                  "type": "string"
                }
              },
              "ImageURL": {
                "description": "URL of the virtual service image",
                "name": "ImageURL",
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "required": [
              "Name",
              "Description",
              "Price",
              "BillingInterval",
              "Features",
              "Addons",
              "ImageURL"
            ]
          }
        }
      },
      "required": [
        "VirtualServiceList"
      ]
    },
    "MainCompanyInformation": {
      "description": "General information about the company",
      "name": "MainCompanyInformation",
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": false,
      "properties": {
        "CompanyOverview": {
          "description": "Overview or 'About Us' information of the company",
          "name": "CompanyOverview",
          "type": [
            "string",
            "null"
          ]
        },
        "TeamStaff": {
          "description": "List of team members or staff",
          "name": "TeamStaff",
          "type": [
            "array",
            "null"
          ],
          "items": {
            "description": "Individual team or staff member",
            "name": "Member",
            "type": "string"
          }
        },
        "ContactDetails": {
          "description": "Various contact details for the company",
          "name": "ContactDetails",
          "type": [
            "object",
            "null"
          ],
          "additionalProperties": false,
          "properties": {
            "Phone": {
              "description": "Company phone number",
              "name": "Phone",
              "type": [
                "string",
                "null"
              ]
            },
            "Email": {
              "description": "Company email address",
              "name": "Email",
              "type": [
                "string",
                "null"
              ]
            },
            "Address": {
              "description": "Company physical address",
              "name": "Address",
              "type": [
                "string",
                "null"
              ]
            },
            "Department": {
              "description": "Specific department contact",
              "name": "Department",
              "type": [
                "string",
                "null"
              ]
            },
            "ContactPerson": {
              "description": "Specific contact person",
              "name": "ContactPerson",
              "type": [
                "string",
                "null"
              ]
            }
          },
          "required": [
            "Phone",
            "Email",
            "Address",
            "Department",
            "ContactPerson"
          ]
        },
        "OpeningHours": {
          "description": "Company opening hours",
          "name": "OpeningHours",
          "type": [
            "string",
            "null"
          ]
        },
        "SocialPlatformLinks": {
          "description": "Links to various social media platforms",
          "name": "SocialPlatformLinks",
          "type": [
            "object",
            "null"
          ],
          "additionalProperties": false,
          "properties": {
            "Facebook": {
              "description": "Link to Facebook page",
              "name": "Facebook",
              "type": [
                "string",
                "null"
              ]
            },
            "Twitter": {
              "description": "Link to Twitter profile",
              "name": "Twitter",
              "type": [
                "string",
                "null"
              ]
            },
            "LinkedIn": {
              "description": "Link to LinkedIn page",
              "name": "LinkedIn",
              "type": [
                "string",
                "null"
              ]
            },
            "Instagram": {
              "description": "Link to Instagram profile",
              "name": "Instagram",
              "type": [
                "string",
                "null"
              ]
            },
            "YouTube": {
              "description": "Link to YouTube channel",
              "name": "YouTube",
              "type": [
                "string",
                "null"
              ]
            }
          },
          "required": [
            "Facebook",
            "Twitter",
            "LinkedIn",
            "Instagram",
            "YouTube"
          ]
        }
      },
      "required": [
        "CompanyOverview",
        "TeamStaff",
        "ContactDetails",
        "OpeningHours",
        "SocialPlatformLinks"
      ]
    },
    "People": {
      "description": "Collection of people associated with the company",
      "name": "People",
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": false,
      "properties": {
        "PersonList": {
          "description": "List of individual people",
          "name": "PersonList",
          "type": "array",
          "items": {
            "description": "Details of a single person",
            "name": "Person",
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "FirstName": {
                "description": "First name of the person",
                "name": "FirstName",
                "type": "string"
              },
              "LastName": {
                "description": "Last name of the person",
                "name": "LastName",
                "type": "string"
              },
              "Email": {
                "description": "Email address of the person",
                "name": "Email",
                "type": [
                  "string",
                  "null"
                ]
              },
              "Phone": {
                "description": "Phone number of the person",
                "name": "Phone",
                "type": [
                  "string",
                  "null"
                ]
              },
              "Mobile": {
                "description": "Mobile number of the person",
                "name": "Mobile",
                "type": [
                  "string",
                  "null"
                ]
              },
              "JobTitle": {
                "description": "Job title of the person",
                "name": "JobTitle",
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "required": [
              "FirstName",
              "LastName",
              "Email",
              "Phone",
              "Mobile",
              "JobTitle"
            ]
          }
        }
      },
      "required": [
        "PersonList"
      ]
    },
    "CustomerSupport": {
      "description": "Information related to customer support",
      "name": "CustomerSupport",
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": false,
      "properties": {
        "FAQ": {
          "description": "List of frequently asked questions",
          "name": "FAQ",
          "type": [
            "array",
            "null"
          ],
          "items": {
            "description": "Individual FAQ item",
            "name": "FAQItem",
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "Question": {
                "description": "The question",
                "name": "Question",
                "type": "string"
              },
              "Answer": {
                "description": "The answer to the question",
                "name": "Answer",
                "type": "string"
              }
            },
            "required": [
              "Question",
              "Answer"
            ]
          }
        },
        "TermsOfService": {
          "description": "Terms of service information",
          "name": "TermsOfService",
          "type": [
            "string",
            "null"
          ]
        },
        "CustomerSupportEmail": {
          "description": "Email address for customer support",
          "name": "CustomerSupportEmail",
          "type": [
            "string",
            "null"
          ]
        },
        "CustomerSupportPhone": {
          "description": "Phone number for customer support",
          "name": "CustomerSupportPhone",
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "FAQ",
        "TermsOfService",
        "CustomerSupportEmail",
        "CustomerSupportPhone"
      ]
    },
    "MarketingAndSales": {
      "description": "Information related to marketing and sales",
      "name": "MarketingAndSales",
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": false,
      "properties": {
        "CustomerReviews": {
          "description": "List of customer reviews or testimonials",
          "name": "CustomerReviews",
          "type": [
            "array",
            "null"
          ],
          "items": {
            "description": "Individual customer review",
            "name": "Review",
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "ReviewText": {
                "description": "The text of the review",
                "name": "ReviewText",
                "type": "string"
              },
              "Reviewer": {
                "description": "Name or identifier of the reviewer",
                "name": "Reviewer",
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "required": [
              "ReviewText",
              "Reviewer"
            ]
          }
        },
        "SpecialOffers": {
          "description": "List of special offers or promotions",
          "name": "SpecialOffers",
          "type": [
            "array",
            "null"
          ],
          "items": {
            "description": "Individual special offer or promotion",
            "name": "Offer",
            "type": "string"
          }
        },
        "UniqueSellingPropositions": {
          "description": "List of unique selling propositions",
          "name": "UniqueSellingPropositions",
          "type": [
            "array",
            "null"
          ],
          "items": {
            "description": "Individual unique selling proposition",
            "name": "USP",
            "type": "string"
          }
        },
        "SalesBenefits": {
          "description": "List of sales benefits",
          "name": "SalesBenefits",
          "type": [
            "array",
            "null"
          ],
          "items": {
            "description": "Individual sales benefit",
            "name": "Benefit",
            "type": "string"
          }
        }
      },
      "required": [
        "CustomerReviews",
        "SpecialOffers",
        "UniqueSellingPropositions",
        "SalesBenefits"
      ]
    }
  },
  "required": [
    "Services",
    "BuildingLocations",
    "MeetingRooms",
    "Offices",
    "Desks",
    "Memberships",
    "VirtualServices",
    "MainCompanyInformation",
    "People",
    "CustomerSupport",
    "MarketingAndSales"
  ]
}

Hi @evom !

I’ve seen similar thing happen to me - a very infrequent occurrence, but it has happened! I noticed it most often happens on the array type, or array-of-objects type, where you have lot of opening/closing braces (GPT-4 likes to insert newline characters as well). It seems to have an issue when emitting these particular tokens.

I would suggest maybe swapping those out just for strings, and doing post-processing yourself.