Skip to main content
Back to Library
Prompt Engineering Guide

Mastering JSON schema generation
on Mixtral 8x22B

Stop guessing. See how professional prompt engineering transforms Mixtral 8x22B's output for specific technical tasks.

The "Vibe" Prompt

"Generate a JSON schema for a 'Product' object. It should have properties for id (string), name (string), description (string, optional), price (number), and categories (array of strings)."
Low specificity, inconsistent output

Optimized Version

STABLE
You are 'SchemaMaster', an expert in JSON Schema draft 2020-12 generation. Your task is to meticulously craft a JSON Schema definition for a given object description. Prioritize clarity, strictness, and common best practices. Follow these steps: 1. **Identify Core Object**: Determine the primary object being described. 2. **Extract Properties**: List all explicit properties, their types, and whether they are required or optional. 3. **Infer Constraints**: For numerical types, consider potential minimum/maximum. For strings, consider `minLength`, `maxLength`, or `pattern` if applicable. For arrays, specify `items` type and `minItems` if relevant. 4. **Apply Best Practices**: Use `title`, `description`, and `$id` (if contextually appropriate, otherwise omit). Prefer primitive types over complex ones unless nested objects are explicitly requested. 5. **Construct Schema**: Based on the extracted information, generate the complete JSON Schema. **Object Description**: A 'Product' object with the following attributes: - `id`: A unique identifier, always a string. - `name`: The product's official name, also a string, and always present. - `description`: An optional string providing more details about the product. - `price`: The current selling price, a positive number. - `categories`: An array containing zero or more strings, each representing a product category. **Schema JSON Output (ONLY THE JSON):**
Structured, task-focused, reduced hallucinations

Engineering Rationale

The optimized prompt leverages several best practices for instruction tuning and robust output generation from large language models like Mixtral 8x22B. 1. **Role Assignment**: 'You are 'SchemaMaster'' sets a persona, encouraging the model to adopt a specific expert mindset and adhere to associated knowledge and styles. 2. **Explicit Task Definition**: 'Your task is to meticulously craft...' clearly defines the goal. 3. **Prioritization**: 'Prioritize clarity, strictness, and common best practices' guides the model's decision-making in ambiguous cases. 4. **Chain-of-Thought (CoT)**: The numbered steps (1-5) force the model to break down the problem into smaller, manageable sub-tasks. This internal reasoning process significantly improves accuracy and completeness, reducing hallucinations or omissions. For JSON schema generation, this ensures properties are identified, types assigned, constraints considered, and best practices applied systematically. 5. **Specific Directives for Schema**: Instructions like 'use `title`, `description`, and `$id`' or 'prefer primitive types' guide the model towards generating higher-quality, standard-compliant schemas. 6. **Clear Delimitation**: 'Object Description:' and 'Schema JSON Output (ONLY THE JSON):' clearly separate the input from the desired output format, reducing the chance of preamble or conversational text. 7. **Positive Constraints**: 'positive number' for price is explicitly highlighted, encouraging the model to add `minimum: 0` or `exclusiveMinimum: 0`. 8. **Array Specifics**: 'array containing zero or more strings' guides the use of `type: "array"` and `items: { type: "string" }` and implicitly suggests `minItems: 0` (or its absence, as 0 is the default). In contrast, the naive prompt is very terse. It relies heavily on the model's inherent understanding of 'JSON schema' and 'Product object' without providing scaffolding for the thought process or specific quality expectations.

0%
Token Efficiency Gain
Generated schema includes `type: "object"` and `properties` key.
Generated schema correctly identifies `id`, `name`, `price`, and `categories` as required.
Generated schema correctly flags `description` as optional.

Ready to stop burning tokens?

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

Optimize My Prompts