0
Convert a free-form chat prompt into a strict JSON-output 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