Skip to main content
Back to Library
Prompt Engineering Guide

Mastering JSON schema generation
on Gemini 1.5 Pro

Stop guessing. See how professional prompt engineering transforms Gemini 1.5 Pro's output for specific technical tasks.

The "Vibe" Prompt

"Generate a JSON schema for a 'Product' object. It should have fields like name, description, price, and category. Make sure price is a number."
Low specificity, inconsistent output

Optimized Version

STABLE
You are a JSON schema generation expert. Your task is to define a robust and comprehensive JSON schema for a 'Product' entity. **Thought Process:** 1. **Identify Core Attributes:** What are the fundamental pieces of information every product must have? 2. **Determine Data Types:** For each identified attribute, what is the most appropriate JSON data type (string, number, boolean, array, object)? 3. **Specify Constraints/Format (if applicable):** Are there any minimums, maximums, patterns, or specific formats (e.g., date-time, email) for the values? 4. **Define Required Fields:** Which attributes are absolutely necessary for a `Product` to be valid? 5. **Consider Optional Fields:** What other attributes might be useful but not strictly mandatory? 6. **Add Descriptions:** Provide clear, concise descriptions for each property to aid understanding. 7. **Example Usage (Optional but helpful):** Provide a simple example of a valid 'Product' object that adheres to the generated schema for clarity. **Schema Generation Task:** Generate a JSON schema for a 'Product' object with the following properties: * `name`: The name of the product. (string, required) * `description`: A detailed description of the product. (string, optional) * `price`: The selling price of the product. (number, required, must be greater than 0) * `category`: The category the product belongs to. (string, required, enum of common categories like 'Electronics', 'Books', 'Clothing', 'Home Goods') * `sku`: Stock Keeping Unit, a unique identifier for the product. (string, required, pattern for alphanumeric codes) * `inStock`: Boolean indicating if the product is currently in stock. (boolean, required) * `dimensions`: An object representing the product's physical dimensions (length, width, height, all numbers, optional). Provide the output strictly as a JSON schema object.
Structured, task-focused, reduced hallucinations

Engineering Rationale

The optimized prompt leverageschain-of-thought prompting by explicitly outlining the steps an expert would take to generate a good schema. It guides the model through identifying attributes, data types, constraints, and required fields. It also clearly separates instructions from the actual task, uses markdown for readability, and provides specific examples/constraints for each field (e.g., 'must be greater than 0', 'enum', 'pattern'). This reduces ambiguity, encourages a more structured output, and allows Gemini 1.5 Pro to better utilize its reasoning capabilities.

0%
Token Efficiency Gain
The optimized prompt generates a more detailed and constrained JSON schema.
The 'price' field in the optimized schema includes a 'minimum' constraint.
The 'category' field in the optimized schema includes an 'enum' constraint.

Ready to stop burning tokens?

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

Optimize My Prompts