How Should an OpenAI API Client Handle a Refusal When JSON Output Is Required?

Asked 14 hours ago 58 views

0

I’m building a feature that asks a model for structured JSON, and most responses match the schema. But what should the client do if the model refuses the request? A refusal message clearly isn’t the same thing as a valid object with the fields my application expects.

Should refusals be handled as a separate response state before schema validation, or is there a recommended way to represent them within the application’s own data model? I’m interested in approaches that avoid brittle parsing and make the refusal visible to the user.

0 Answers


Write Your Answer