π€ Leon LLM JSON API
Structured data extraction in ComfyUI β the LLM node that returns schema-validated JSON
- input_image
- image_array
- json_response
Leon LLM JSON API is the sibling of the pack's chat node, and it exists to solve the problem plain chat calls have when you want a machine-readable answer. You give it a user message plus a JSON schema, and it asks the model to return structured data matching that schema - validated by the endpoint's json_schema response format, not by your hopes and prayers. If you've ever tried to parse an LLM's free-form reply for a value and watched it fail on a trailing comma, you know why this node exists.
The workflow it enables is the pack README's "Data Extraction" pattern: a text block goes in, a JSON schema describes the shape of the answer, and out comes a json_response string you can hand to any downstream node that consumes JSON. The default schema extracts an email address from text - small, but it shows the shape of the thing.
How it works
Same LLM base class as the chat node: build messages, POST to https://api.hyprlab.io/v1/chat/completions with a Bearer token, retry up to 5 times on failure. The difference is the payload: it includes a response_format of type json_schema carrying your json_schema string, which is how the model is constrained to emit valid JSON matching your shape. The node parses your schema first (a malformed schema raises a clear error before you burn a call).
The inputs that matter:
json_schema- the schema, as a JSON string. This is the contract: whatever properties you declare here are what the model commits to returning. Defaults to{"type": "object", "properties": {"email": ...}, "required": ["email"]}.user_message- the text to extract from, plus the instruction. The default ("Extract the email address from this text: Contact us at [email protected]") is a decent template.system_message- defaults to "You are a helpful assistant that extracts structured data."temperature- defaults to 0.1, and the tooltip tells you why: "lower for more consistent JSON". Leave it there.model- free-form model string; defaults to empty, so pair it with the Model Selector.- Same vision inputs as the chat node (
input_image,image_url,image_array) if you want to extract from an image.
Single output: json_response (STRING).
Installing it
Pack-wide install:
cd ComfyUI/custom_nodes
git clone https://github.com/l3ony2k/comfyui-leon-nodes
pip install -r requirements.txt
Restart ComfyUI, or install "ComfyUI Leon Nodes" via ComfyUI Manager.
Where people get burned
The schema is where it all goes wrong: it must be valid JSON, it must be a schema your endpoint's json_schema mode supports, and required fields you declare will actually be enforced - if you ask for a key the model can't find, you'll get a structured failure or a stub. The empty model default means forgetting to wire a Model Selector gets you a hard error. And the pack's usual retry behavior applies: bad keys fail slowly. The output is still a string, not a parsed object, so you'll need a JSON-parse node downstream if your next step needs an actual value. For turning free text into tidy, schema-shaped data inside a graph, it's the right tool.
Inputs (11)
| Name | Type | Default | Description |
|---|---|---|---|
| model | STRING | Model name to use for JSON completion | |
| user_message | STRING | Extract the email address from this text: Contact us at [email protected] | User message to send to the model |
| json_schema | STRING | {"type": "object", "properties": {"email": {"type": "string", "description": "The extracted email address"}}, "required": ["email"]} | JSON schema for structured output |
| api_url | STRING | https://api.hyprlab.io/v1/chat/completions | API URL for chat completions |
| api_key | STRING | YOUR_HYPRLAB_API_KEY | Your HyprLab API key |
| system_messageopt | STRING | You are a helpful assistant that extracts structured data. | System message to set the assistant's behavior |
| max_tokensopt | INT | 1280001β1048576 | Maximum number of tokens to generate |
| temperatureopt | FLOAT | 0.10β2 | Sampling temperature (lower for more consistent JSON) |
| input_imageopt | IMAGE | Optional single image input for vision-capable models | |
| image_urlopt | STRING | Optional image URL for vision-capable models | |
| image_arrayopt | IMAGE_ARRAY | Optional array of images (base64 or URLs) for vision-capable models |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| json_response | STRING | β |