Skip to main content
Back to Library
Prompt Engineering Guide

Mastering JSON schema generation
on Qwen 2.5 72B

Stop guessing. See how professional prompt engineering transforms Qwen 2.5 72B's output for specific technical tasks.

The "Vibe" Prompt

"Generate a JSON schema for the following JSON object: ${json_object}. Make sure it's valid."
Low specificity, inconsistent output

Optimized Version

STABLE
You are an expert JSON schema generator. Your goal is to produce a JSON schema (draft 2020-12) for the provided JSON object. Ensure the schema is precise, complete, and adheres to best practices, including appropriate types, required fields, and array item definitions. Explain your thought process step-by-step before outputting the final JSON schema. JSON Object to analyze: ```json ${json_object} ``` Thought Process: 1. Identify the root type (object or array). 2. If it's an object, iterate through its properties: a. Determine the data type for each property (string, number, boolean, array, object, null). b. If the property is an object, recursively apply this process. c. If the property is an array, determine the type of its elements. d. Identify any potentially required fields based on their presence in the example. 3. If it's an array, determine the type of its elements. 4. Construct the schema ensuring all identified types, properties, and constraints are included. Explicitly define 'required' arrays where applicable. Pay attention to `additionalProperties` for objects and `additionalItems` for arrays. JSON Schema:
Structured, task-focused, reduced hallucinations

Engineering Rationale

The optimized prompt leverages chain-of-thought prompting, guiding the model through a structured thought process for schema generation. By explicitly stating the steps, it forces the model to reason about each part of the JSON object, leading to a more accurate and comprehensive schema. It also establishes the model's persona as an 'expert JSON schema generator' and specifies the schema draft ('draft 2020-12'), providing clear boundaries and expectations. The clear separation between thought process and final output also aids clarity. It requests `additionalProperties` and `additionalItems` considerations, which are often overlooked in simpler prompts.

0%
Token Efficiency Gain
The generated schema must be valid JSON.
The generated schema must correctly identify all primitive types (string, number, boolean, null).
The generated schema must correctly identify array types and their item structures.

Ready to stop burning tokens?

Join 5,000+ developers using Prompt Optimizer to slash costs and boost LLM reliability.

Optimize My Prompts