Prompt Engineering Guide
Mastering JSON schema generation
on GPT-4o
Stop guessing. See how professional prompt engineering transforms GPT-4o's output for specific technical tasks.
The "Vibe" Prompt
"Generate a JSON schema for a 'Product' object. It should have a name, price, description, and an array of tags. Price should be a number."
Low specificity, inconsistent output
Optimized Version
You are an expert in JSON Schema draft 2020-12. Your task is to generate a JSON schema object for a 'Product' based on the requirements below. Ensure the schema is valid and accurately reflects every detail.
### Requirements:
1. **Object Name:** Product
2. **Properties:**
* `name`: A string representing the product's name. It must be required.
* `price`: A floating-point number representing the product's price. It must be required and non-negative.
* `description`: An optional string providing a detailed description of the product.
* `tags`: An array of strings. Each string represents a tag associated with the product. This property is optional, but if present, the array must not be empty and each tag should have a minimum length of 1 character.
### Chain of Thought:
1. Start with the base `type: "object"` and `$schema` declaration.
2. Define the `properties` block, iterating through each required and optional property.
3. For `name`: Set `type: "string"`, mark as required.
4. For `price`: Set `type: "number"`, add `minimum: 0`, mark as required.
5. For `description`: Set `type: "string"`, do not mark as required.
6. For `tags`: Set `type: "array"`. Add `items: { type: "string", minLength: 1 }`. Add `minItems: 1` to ensure it's not empty if present. Do not mark as required as per requirement.
7. Compile the `required` array based on steps 3 and 4.
8. Review the generated schema against all requirements to ensure accuracy and completeness.
### Output Format:
Provide only the JSON schema object. Do not include any additional text or explanations outside the JSON.
Structured, task-focused, reduced hallucinations
Engineering Rationale
The optimized prompt provides clear role-playing, explicitly outlines all requirements in a structured list, and includes a detailed chain-of-thought. This guides the model step-by-step through the schema generation process, reducing ambiguity and increasing the likelihood of a correct and complete output the first time. The explicit mention of JSON Schema draft and output format further constrains the model.
0%
Token Efficiency Gain
Optimized prompt is significantly longer than the naive prompt.
Optimized prompt's output quality for schema generation will be higher and more consistent.
The chain-of-thought explicitly guides the model on how to handle each property's constraints.
Ready to stop burning tokens?
Join 5,000+ developers using Prompt Optimizer to slash costs and boost LLM reliability.
Optimize My Prompts