Skip to content
UsecaseBoard
← All use cases
lobstersStructured Output

Repair generated JSON with the validator's actual error messages

At a glance

A developer reports better JSON corrections when the same chat receives the errors from schema validation. This workflow is listed under Structured Output, Validation, Error Feedback.

SourceBuilding a tool for these workflows? See weekly rates.

What they did

1) Start with the JSON Schema your application expects, a validator that can check it, and the model-generated response you need to consume. The Lobsters discussion concerns structured output for a role-playing application. 2) Validate the response against the schema rather than relying on regular expressions to decide whether its structure is acceptable. 3) If validation fails, continue the same model conversation. Explain that the response did not match the expected schema and paste the validator's actual error details so the model can revise it. 4) Validate the revised response again before using it downstream. The practical endpoint is a response that passes your checks; the correction request alone is not validation.

How it went

The commenter reported that this feedback loop often made ChatGPT fix mistakes; no success rate was supplied.

Save ideas in this browser. Upvotes count across the board.

Prompt excerpt

that seems to not quite match, I got this error when I validated the reply according to the schema: ${schema error}

Sponsored

CodeBuddy

Tencent Cloud AI coding assistant for IDE and CLI.

Try CodeBuddy ↗
Explore all →