Reference · Tools

Grok Structured Output

Get structured JSON responses from xAI Grok with schema enforcement.

Action AI v1

Grok Structured Output returns typed JSON rather than prose, sending your schema to the xAI API as a constraint so the model's reply matches it exactly. The parsed object arrives ready for the next node to read. Use it whenever downstream steps need reliable fields — pulling entities out of documents, or classifying records into a fixed set of categories.

Node type
Action
Parameters
7
Outputs
Output, Error
Credentials
xAI

Grok Structured Output

Get structured JSON responses from xAI Grok with schema enforcement.

Overview

Grok Structured Output sends a user message to the xAI Grok API with a JSON schema constraint, forcing the model to return valid JSON matching the provided schema. Supports model selection, system prompts, temperature, max tokens, and strict mode. Returns the parsed structured JSON, model name, token usage, and finish reason.

Category: AI
Tool Name: grok_structured_output
Version: 1

Appearance: Icon: brain | Color: #000000

Node Type

Action — processes input items and produces output

Input / Output

DirectionPort(s)
InputInput
OutputOutput, Error

Credentials

This tool requires xAI credentials. See the Credentials Guide for setup instructions.

Parameters

ParameterTypeRequiredDefaultDescription
ModeloptionsNoPlatform defaultThe Grok model to use for structured output generation.
Options: the Grok chat models currently available — the dropdown tracks the model catalog, so it changes as xAI’s line-up changes.
System PromptstringNoOptional system prompt to set the behavior and context for the model. Supports expressions like {{ $json.persona }}.
User MessagestringYesThe user message to send to Grok. If empty, falls back to the input item’s “message” or “prompt” field. Supports expressions.
JSON SchemajsonYes{}The JSON Schema that the model response must conform to. Can be a JSON object or a string that will be parsed.
OptionscollectionNo{}Optional generation and output settings — add only the fields you want to override.
— TemperaturenumberNo1Controls randomness. Lower values make output more focused; higher values more creative. Range: 0-2.
— Max TokensnumberNo4096Maximum number of tokens to generate in the response.
— StrictbooleanNotrueEnable strict schema enforcement. When true, the model is constrained to only produce output matching the exact schema.
— Response Field NamestringNostructuredThe output field name where the parsed structured JSON will be stored.
Include InputbooleanNofalseWhether to include the original input item fields in the output alongside the structured response.
Max ConcurrencynumberNo10Maximum number of items to process concurrently.

Output Data

One output item per input item. The parsed object is written to the field named by Response Field Name (structured by default). The rest of the input JSON is carried over only when Include Input is on; binary data from the input item is forwarded.

  • structured — the parsed JSON object matching your schema, under whatever name Response Field Name is set to.
  • model — the model that produced the response.
  • usage — the token counts reported by xAI for the request.
  • finishReason — why generation stopped, as reported by xAI.

If the model’s reply cannot be parsed as JSON, the response field holds _raw (the unparsed text) and _parseError (the parser message) instead of your schema’s fields — a useful thing to branch on downstream.

Reference the result downstream by expression, e.g. {{ $json.structured.sentiment }}.

Usage Examples

  • Extract structured data from unstructured text using a JSON schema
  • Parse entities from a document into a defined JSON format with Grok
  • Generate structured product descriptions matching a schema
  • Convert free-text responses into typed JSON objects with strict mode
  • Use Grok to classify items and return results in a fixed schema

Example Configuration

Classify a review into a fixed shape:

{
  "type": "grok_structured_output",
  "parameters": {
    "systemPrompt": "You are a precise sentiment analysis engine.",
    "userMessage": "Analyse the sentiment of this review: {{ $json.reviewText }}",
    "jsonSchema": {
      "type": "object",
      "properties": {
        "sentiment": { "type": "string", "enum": ["positive", "neutral", "negative"] },
        "confidence": { "type": "number", "minimum": 0, "maximum": 1 },
        "reasoning": { "type": "string" }
      },
      "required": ["sentiment", "confidence", "reasoning"],
      "additionalProperties": false
    },
    "includeInput": true,
    "options": {
      "temperature": 0.1,
      "maxTokens": 512,
      "strict": true
    }
  }
}

Extract named entities into a custom output field:

{
  "type": "grok_structured_output",
  "parameters": {
    "userMessage": "Extract all named entities from: {{ $json.text }}",
    "jsonSchema": {
      "type": "object",
      "properties": {
        "people": { "type": "array", "items": { "type": "string" } },
        "organizations": { "type": "array", "items": { "type": "string" } },
        "locations": { "type": "array", "items": { "type": "string" } }
      },
      "required": ["people", "organizations", "locations"],
      "additionalProperties": false
    },
    "options": {
      "temperature": 0,
      "maxTokens": 2048,
      "responseFieldName": "entities"
    }
  }
}

Error Handling

ModeBehavior
stopHalts workflow on first error
continueSkips failed items, passes successful ones through
errorPortRoutes failed items to Error output port

Tips

Grok Structured Output sends a prompt to the xAI Grok API with a JSON schema constraint, forcing the model to return valid JSON that exactly matches the provided schema. Use it when downstream workflow nodes require machine-readable, typed data such as extracted entities, classifications, or structured records rather than free-form text. It produces the parsed JSON object, the Grok model variant used, prompt and completion token counts, and the finish reason.

Frequently asked questions

How strictly is the schema enforced?

The schema is sent as a constraint on the request, so the model must return JSON matching it rather than being asked politely in the prompt. That is what makes the output safe to read positionally downstream.

What does the node output?

The parsed JSON object, the Grok model variant used, prompt and completion token counts, and the finish reason.

How does it compare to Claude Structured Output?

Same goal, different mechanism and provider: this constrains the response with a JSON schema on the xAI API, while the Claude node forces a tool call whose input_schema is the shape. Pick by which model you want and which credential you hold.

What happens if the model cannot satisfy the schema?

The item fails and routes to the Error output when error handling is set to continue using the error output, so one impossible record does not stop the batch.

Build with the Grok Structured Output node

Drop it into a workflow, wire it to an agent, or call it on a schedule. You'll need xAI credentials first.

Open BusyBot

Last updated . Spotted something wrong? Tell us.