0
Convert a free-form chat prompt into a strict JSON-output prompt
⁂auto-checked, 3 days oldAauraNovice
The prompt
I have a prompt designed for conversational, free-text output and I need to convert it to produce strict, parseable JSON matching a schema, for use in a pipeline. Given the original prompt: original_prompt and the target schema: target_schema
1. Map each piece of information the original prompt asks for into a specific schema field, and flag anything the original asks for that doesn't map cleanly (information that's inherently free-text/nuanced and would be lossy forced into a fixed field) so we decide together how to handle it rather than silently cramming it in.
2. Add explicit instructions for the model to never wrap the JSON in markdown code fences or add explanatory text before/after, since that breaks naive parsers, and note that this needs to be tested since models don't always comply perfectly.
3. Specify what the model should output for fields where information is genuinely absent from the input (null vs omitting the field vs an empty string) and be consistent, since inconsistent null-handling breaks downstream parsing.
4. Add a instruction for how to handle a case where the input doesn't fit the schema at all (e.g. asked to extract order details from a message that isn't actually an order) - a fixed error-shape response, not an empty or malformed JSON guess.
5. Give the final prompt text, ready to use.
Original prompt: original_prompt
Target schema: target_schema
Where it has been run
| Model | Version | People | Broke | Auto | Last |
|---|---|---|---|---|---|
| Claude | Haiku 4.5 | 0 | 0 | 1/1 | 3 days ago |
Example output
Mapping: 'summarize the customer's issue' maps to `issue_summary: string`, straightforward. Flagged: the original also asks the model to 'note anything else notable', this is inherently open-ended and doesn't map cleanly to a fixed field, recommend either a `notes: string | null` catch-all field (some information loss acceptable) or dropping this instruction from the JSON version entirely if it's not actually consumed downstream, your call.
Final prompt excerpt: 'Output ONLY valid JSON matching the schema below. Do not wrap it in markdown code fences, do not add any text before or after the JSON object.'
Null handling: for fields where the input doesn't contain the information, output `null`, not an empty string and not an omitted key, every schema field must always be present in the output for consistent parsing.
No-fit handling: 'If the input does not describe a customer order at all, output exactly `{"error": "not_an_order", "raw_input_summary": "<one sentence>"}` instead of attempting to fill the order schema with guessed or null values.' This gives the pipeline a clean, detectable error shape instead of a malformed or misleading partial object.
0 comments
Sign in to comment or report what this prompt did for you.
Sign inNo comments yet. Run the prompt and report what you got.