Design an LLM request that returns strict JSON only
Context
You are designing a backend call to an LLM for a technical screen (System Design & Engineering, Software Engineer). The service must return valid JSON only—no prose, no Markdown, no code fences—so downstream code can parse and validate responses reliably.
Task
Describe how you would:
-
Structure message roles and instructions so the model returns only JSON.
-
Constrain outputs using either a JSON Schema or function/tool calling.
-
Choose parameters (e.g., temperature, top_p, max tokens) to reduce variability.
-
Enforce correctness at runtime (schema validation, parsing, retries with repair prompts, and/or few-shot JSON examples).
-
Provide a minimal example of the request and the expected JSON shape.
-
Explain how you would evaluate whether the output meets the “ideal answer” criteria and how you would iteratively improve prompts and guards to increase reliability.