Skip to main content
Back to Library
Prompt Engineering Guide

Mastering JSON schema generation
on Perplexity Online 70B

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

The "Vibe" Prompt

"Generate a JSON schema for the following data:"
Low specificity, inconsistent output

Optimized Version

STABLE
You are an expert in JSON schema design and effective prompt engineering. Your task is to generate a JSON schema and NOTHING ELSE. Utilize a chain-of-thought approach to ensure comprehensive and accurate schema generation for the provided data. **Data Context/Purpose:** [Insert brief description of the data's context or purpose here, e.g., 'This data represents a user profile, emphasizing contact information and preferences.'] **Data Examples (if available, enclose in triple backticks): ```json [Insert 1-3 representative JSON data examples here, or state 'N/A' if no examples are provided.] ``` **Instructions for Schema Generation:** 1. **Infer Types:** Determine the most appropriate JSON data type (string, number, boolean, array, object, null) for each field. 2. **Identify Required Fields:** Explicitly mark fields that are mandatory (`"required": [...]`). 3. **Define Enums:** If a field has a limited set of possible values, define them using the `"enum": [...]` keyword. 4. **Format Validation:** Apply `"format"` keywords (e.g., `"email"`, `"uri"`, `"date-time"`, `"ipv4"`) where applicable. 5. **Pattern Validation:** Use `"pattern"` (regex) for string fields requiring specific formats (e.g., phone numbers). 6. **Range Constraints:** For numbers, use `"minimum"`, `"maximum"`, `"exclusiveMinimum"`, `"exclusiveMaximum"`. 7. **Length Constraints:** For strings, use `"minLength"`, `"maxLength"`. For arrays, use `"minItems"`, `"maxItems"`. 8. **Array Item Definition:** For arrays, define the `"items"` field specifying the type or schema of array elements. If heterogeneous, consider `"prefixItems"` or `"contains"`. 9. **Object Property Definition:** For objects, define `"properties"` and consider `"additionalProperties": false` if unknown properties are disallowed. 10. **Descriptions:** Add a concise `"description"` for complex objects or fields where clarity is beneficial. 11. **Titles/IDs:** Consider `"$id"` for the root schema and `"title"` for the schema's purpose. 12. **Defaults:** If a field has a common default value, include `"default": ...`. **Chain of Thought Steps (DO NOT GENERATE THIS PART, IT'S FOR YOUR INTERNAL PROCESS): - Analyze the provided data examples and context. - Break down the data into its constituent fields. - For each field, apply instructions 1-12 systematically. - Ensure all inferred constraints and types are consistent and robust. - Construct the final JSON schema object. **BEGIN JSON SCHEMA GENERATION:** ```json [Your schema will appear here] ```
Structured, task-focused, reduced hallucinations

Engineering Rationale

The optimized prompt works by providing extensive context, explicit instructions, and a simulated chain-of-thought process. It forces the model to methodically consider various JSON schema features, leading to a much more detailed, accurate, and robust schema. By emphasizing 'NOTHING ELSE' and using clear delimiters for the output, it also minimizes extraneous text. The structured instructions guide the model through best practices for schema design, preventing omitted constraints or incorrect type inferences. The placeholder for 'Data Context/Purpose' and 'Data Examples' allows for crucial input that helps the model understand the real-world implications of the data, which is vital for effective schema generation.

0%
Token Efficiency Gain
The generated schema must correctly infer all basic data types (string, number, boolean, array, object).
All fields that are clearly mandatory from the data context or examples must be marked as 'required'.
Where applicable, 'format' (e.g., email, date-time) or 'pattern' validations should be used.

Ready to stop burning tokens?

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

Optimize My Prompts