Skip to main content
Back to Library
Prompt Engineering Guide

Mastering JSON schema generation
on Claude 3.5 Haiku

Stop guessing. See how professional prompt engineering transforms Claude 3.5 Haiku's output for specific technical tasks.

The "Vibe" Prompt

"Generate a JSON schema for the following JSON object: [PASTE_JSON_HERE]"
Low specificity, inconsistent output

Optimized Version

STABLE
You are an expert JSON schema generator. Your goal is to create a precise and robust JSON schema. Follow these steps: 1. **Analyze the input JSON object:** Carefully examine the structure, data types, and potential constraints of each field. 2. **Infer data types:** Determine the appropriate `type` for each field (e.g., `string`, `number`, `boolean`, `array`, `object`, `null`). For arrays, infer the `items` type. For objects, infer `properties`. 3. **Identify required fields:** Based on typical data patterns and the presence of the field in the example, mark fields as `required` where appropriate. Assume fields present in the example are required unless explicitly stated otherwise by a user or if the data itself suggests optionality (e.g., an array that might sometimes be empty). 4. **Suggest formats for strings:** If a string field appears to be an email, URL, date, date-time, or UUID, add a `format` keyword (e.g., `"format": "email"`). 5. **Infer additional constraints:** - For numbers: `minimum`, `maximum` (if a clear range is evident). - For strings: `minLength`, `maxLength`, `pattern` (if a clear regex is evident). - For arrays: `minItems`, `maxItems`, `uniqueItems` (if applicable). - For objects: `minProperties`, `maxProperties` (if applicable). 6. **Add descriptions:** For each top-level property and significant nested property, provide a concise `description` explaining its purpose. 7. **Construct the schema:** Assemble all inferred types, constraints, and descriptions into a valid JSON Schema Draft 7 or later. Here is the JSON object for which to generate the schema: [PASTE_JSON_HERE]
Structured, task-focused, reduced hallucinations

Engineering Rationale

The optimized prompt leverages chain-of-thought by breaking down the task into sequential, logical steps. It explicitly instructs the model on how to analyze, infer, and structure the schema, guiding it to consider various JSON Schema keywords. It also assigns an 'expert' persona, which subtly encourages better performance. By providing clear instructions for inferring data types, required fields, formats, and other constraints, it reduces ambiguity and the likelihood of omissions or incorrect assumptions compared to the naive 'vibe' prompt. The request for descriptions also adds semantic value to the generated schema.

0%
Token Efficiency Gain
The 'optimized_prompt' encourages more detailed schema generation.
The 'optimized_prompt' guides the model to include `format` and constraint keywords.
The 'optimized_prompt' explicitly asks for `description` fields.

Ready to stop burning tokens?

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

Optimize My Prompts