ComfyUI Node

πŸ€– Leon LLM JSON API

Structured data extraction in ComfyUI β€” the LLM node that returns schema-validated JSON

By l3ony2kΒ·Created about a year agoΒ·Updated 2 months agoΒ· 3
πŸ€– Leon LLM JSON API
  • input_image
  • image_array
  • json_response
β—„modelβ–Ί
β—„user_messageExtract the email address from this text: Contact us at [email protected]β–Ί
β—„json_schema{"type": "object", "properties": {"email": {"type": "string", "description": "The extracted email address"}}, "required": ["email"]}β–Ί
β—„api_urlhttps://api.hyprlab.io/v1/chat/completionsβ–Ί
β—„api_keyYOUR_HYPRLAB_API_KEYβ–Ί
β—„system_messageYou are a helpful assistant that extracts structured data.β–Ί
β—„max_tokens128000β–Ί
β—„temperature0.1β–Ί
β—„image_urlβ–Ί

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.

CategoryLeon_API

Inputs (11)

NameTypeDefaultDescription
modelSTRINGModel name to use for JSON completion
user_messageSTRINGExtract the email address from this text: Contact us at [email protected]User message to send to the model
json_schemaSTRING{"type": "object", "properties": {"email": {"type": "string", "description": "The extracted email address"}}, "required": ["email"]}JSON schema for structured output
api_urlSTRINGhttps://api.hyprlab.io/v1/chat/completionsAPI URL for chat completions
api_keySTRINGYOUR_HYPRLAB_API_KEYYour HyprLab API key
system_messageoptSTRINGYou are a helpful assistant that extracts structured data.System message to set the assistant's behavior
max_tokensoptINT1280001–1048576Maximum number of tokens to generate
temperatureoptFLOAT0.10–2Sampling temperature (lower for more consistent JSON)
input_imageoptIMAGEOptional single image input for vision-capable models
image_urloptSTRINGOptional image URL for vision-capable models
image_arrayoptIMAGE_ARRAYOptional array of images (base64 or URLs) for vision-capable models

Outputs (1)

NameTypeDescription
json_responseSTRINGβ€”