ZML_LLM JSON结构定义
Teach your LLM node what 'structured output' means
- JSON结构
If you've ever asked an LLM for JSON and gotten a prose paragraph instead, you understand why ZML_LLM_JsonSchema exists. It's the ZML pack's way of telling the chat node "no, really, return me a structure" - and it's about as simple as a node gets.
The whole thing is one multiline text box: schema_string. You type a JSON object that describes the shape you want back, and the node json.loads() it and emits a JSON结构 (JSON_SCHEMA) output. That output plugs into the optional json_schema input on ZML_LLM_Chat. The default value is a two-field example - a 回复内容 string and a 状态 array - which is a decent template for "give me text plus a list of attributes."
The clever part is what the Chat node does with it. Depending on your json_strategy, that schema either gets injected into the system prompt as an output-format requirement, or (in "OpenAI strict mode") passed as a real response_format: json_schema parameter so the API enforces it server-side. So this node isn't doing heavy lifting - it's just a convenient place to define the contract once and keep it visible in the graph, instead of burying a big JSON blob inside a prompt string.
Realistic uses: you want a captioner that returns {"subject": "...", "tags": [...]}, a batch of image descriptions in a fixed shape, or any downstream node that needs to json.loads a reply reliably. The ZML pack even ships a JSON extractor node (ZML_JsonExtractor) that takes the reply and pulls named keys out, which is the natural downstream of this whole pipeline.
Two gotchas. First, if you paste invalid JSON the node doesn't crash - it outputs {"error": "Invalid JSON"}, and the Chat node checks for that and skips the schema quietly. So a typo silently downgrades you to unformatted output. Watch for trailing commas; they're legal in hand-written JSON-with-comments but not in strict json.loads. Second, remember the schema's keys are the keys the model is expected to produce - keep them in the same language you want your output in. The example uses Chinese keys, which is fine, but your extractor downstream has to reference the exact same key names.
It's a 300-word kind of node: zero dependencies, no models, no network. Install the pack (Manager search "ComfyUI-ZML-Image", or git clone https://github.com/zml-w/ComfyUI-ZML-Image into custom_nodes and restart), find it under ZML 图像 → LLM, and paste a JSON shape. If you're not using the ZML LLM stack at all, you don't need it - but if you are, it's the difference between parsing a model's free-form rambling and actually receiving a structure you can wire into a file saver.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| schema_string | STRING | { "回复内容": "在此输入", "状态": ["心情", "手部动作", "表情细节"] } | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| JSON结构 | JSON_SCHEMA | — |