Skip to main content
Back to Library
Prompt Engineering Guide

Mastering JSON schema generation
on Llama 3.1 70B

Stop guessing. See how professional prompt engineering transforms Llama 3.1 70B's output for specific technical tasks.

The "Vibe" Prompt

"Generate a JSON schema for the following CSV data description: 'A list of products with their name, price, and whether they are in stock. The price should be a number, name a string, and in_stock a boolean.'"
Low specificity, inconsistent output

Optimized Version

STABLE
You are an expert in JSON schema generation and a meticulous programmer. Your task is to generate a JSON Schema Draft 2020-12 representing the provided data description. Follow these steps meticulously: 1. **Understand the Request:** Carefully read the data description provided to identify all entities, their relationships, and their individual data types, constraints, and descriptions. 2. **Identify Top-Level Structure:** Determine if the data represents a single object, an array of objects, or a primitive value. In this case, it's 'A list of products', which implies an array. 3. **Define Item Structure (if array):** For each item in the list (a 'product'), identify its properties. * `name`: Described as 'name', should be a 'string'. * `price`: Described as 'price', should be a 'number'. * `in_stock`: Described as 'whether they are in stock', should be a 'boolean'. 4. **Enforce Required Properties:** Determine which properties are mandatory. Based on the description, all three (`name`, `price`, `in_stock`) appear to be essential for a product. 5. **Assemble the Schema:** Construct the JSON schema using the identified types, properties, and constraints, ensuring it adheres to Draft 2020-12. 6. **Add Metadata (Optional but Recommended):** Include a `$schema` directive and potentially a `title` or `description` for clarity. **Data Description:** 'A list of products with their name, price, and whether they are in stock. The price should be a number, name a string, and in_stock a boolean.' **Thought Process for Schema Generation:** [Your detailed step-by-step thinking would go here, leading to the schema.] **Generated JSON Schema:**
Structured, task-focused, reduced hallucinations

Engineering Rationale

The `optimized_prompt` works by breaking down the complex task of schema generation into smaller, manageable steps. This 'chain-of-thought' approach guides the model through a logical reasoning process, ensuring it covers all necessary aspects of JSON schema design. It explicitly asks the model to 'Understand the Request', 'Identify Top-Level Structure', 'Define Item Structure', 'Enforce Required Properties', and 'Assemble the Schema'. By requiring the model to articulate a 'Thought Process', it further encourages deeper reasoning and reduces the likelihood of omissions or incorrect interpretations. The explicit mention of 'Draft 2020-12' ensures consistency with a standard. This structured approach mirrors how a human expert would approach the task, leading to higher accuracy and completeness, especially for more complex schema requirements.

0%
Token Efficiency Gain
The 'optimized_prompt' should consistently produce a Draft 2020-12 schema.
The 'optimized_prompt' should always include 'type: array' at the top level for 'A list of products'.
The 'optimized_prompt' should accurately infer 'name: string', 'price: number', and 'in_stock: boolean' within the item definition.

Ready to stop burning tokens?

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

Optimize My Prompts