Prompt LibraryEngineering

LLM Structured Output Contract & Validator Prompt

Pair a strict output schema with the exact validation code to enforce it.

The prompt

Desired output: {{description}}

Write the JSON schema for it, then write a validation function in {{language}} that checks: required fields present, types correct, enums respected, and no extra top-level keys.
State what the calling code should do on validation failure: retry with the error appended to the prompt, or fail closed.

Replace the {{fields}} with your own context and tighten the rules to match your domain.

Share this prompt