{
 "schema_version": 1,
 "generated": "2026-10-24",
 "id": "deepseek-ai-deepinfer--constrain-model-output-to-json-schema",
 "repo": "deepseek-ai/DeepInfer",
 "repo_url": "https://github.com/deepseek-ai/DeepInfer",
 "repo_slug": "deepseek-ai-deepinfer",
 "title": "Force model output to match a JSON schema",
 "page_title": "How to force model output to match a JSON schema with Deep Infer",
 "summary": "Use structured outputs to limit generation to a regex, JSON schema, or EBNF grammar.",
 "who": "A developer building a pipeline that needs the model to return machine-readable JSON with a fixed shape.",
 "problem": "Free-form model text is hard to parse, and retries on malformed output waste time.",
 "outcome": "Generated text that follows the schema you pass in, ready for a parser.",
 "steps": [
  "Open `examples/_structured_output.py` and read how it builds the constraint.",
  "Define your JSON schema as a Python dict.",
  "Pass `so_args={\"schema_type\": ..., \"schema\": ...}` to `SamplingParams` with your schema type and schema.",
  "Run the offline example with your prompt and parse the returned text as JSON."
 ],
 "agent_prompt": "In the DeepInfer repo, follow examples/_structured_output.py to constrain generation with so_args for the schema in <schema file>. Output the generated JSON for the prompt <prompt>. Verify that the output parses with json.loads and matches the schema's required keys.",
 "agents": [
  "any"
 ],
 "difficulty": "Intermediate",
 "time": "1 hour",
 "basis": "readme",
 "caveat": "The README does not list which schema types are supported beyond regex, JSON schema, and EBNF grammar, so check the example file before you rely on a specific type.",
 "category": "Software and DevOps",
 "tags": [
  "Software and DevOps"
 ],
 "lang": "python",
 "requirements": [
  "Linux with GCC 13.0 or newer and Python 3.12",
  "NVIDIA SM100 GPU with CUDA 13, or Huawei Ascend 950 NPU with CANN 9.2",
  "Access to the deepseek-ai/DeepSeek-V4.1-Flash-1017 checkpoint on Hugging Face, or a local copy",
  "Enough disk space and memory for the checkpoint and the build"
 ],
 "risk": "none",
 "seen_in_the_wild": false,
 "mentioned_publicly": false,
 "risks": [],
 "best": false,
 "score": 0.8,
 "evidence": [],
 "url": "https://dedupedai.com/use-cases/deepseek-ai-deepinfer/constrain-model-output-to-json-schema/",
 "md": "https://dedupedai.com/use-cases/deepseek-ai-deepinfer/constrain-model-output-to-json-schema/index.md",
 "disclaimer": "Deduped lists open-source repositories that belong to other people. We do not own, maintain, audit, or vouch for any of them, and a repo appearing here is not an endorsement or a safety check. The use cases, steps, and prompts are written by AI and may be incomplete, outdated, or just wrong. Where a use case is marked \"Seen in the wild\", we link to public posts where someone described something similar, but we have not verified those posts and the use case itself is still our AI's own write-up. Use all of this at your own risk. Only run code, commands, or agents on systems and accounts you are authorized to use, and read the code and every command before you run it, especially anything that touches credentials, files, or the network. Nothing here is professional, security, legal, or financial advice. All trademarks and project names belong to their respective owners, and their use here does not imply affiliation. Content is provided as is, without warranties of any kind. Found a mistake, a safety problem, or something you want removed? Email hello@dedupedai.com and we will look at it promptly.",
 "api": "https://dedupedai.com/api/v1/usecases/deepseek-ai-deepinfer--constrain-model-output-to-json-schema.json",
 "api_version": "v1"
}
