OpenClaw Structured Extraction with JSON Schema: Build Reliable Agent Outputs
An agent answer is easy for a person to read and surprisingly difficult for software to trust. A sentence such as “The incident is probably resolved” may be useful in a chat, but it is not a dependable input for a notification router, a browser monitor, or a workflow that needs to decide what happens next.
Structured extraction gives that answer a contract. Instead of asking OpenClaw for “valid JSON” and hoping for the best, you define the fields, types, and constraints that the result must satisfy. OpenClaw’s optional llm-task tool can make a JSON-only model call and validate the parsed result against a JSON Schema before returning it.
This guide shows how to design that contract, configure the tool, and use the result safely. It also covers the related browser-monitoring pattern: extracting a small, stable object so a page-change check compares meaning rather than the entire page.
Quick Answer: What Does JSON Schema Validation Solve?
JSON Schema validation checks whether an extracted result has the required shape and data types. For example, a schema can require a status string, an integer openItems count, and an array of nextSteps strings. It can reject a response that omits status, returns a word where a number is required, or uses a status outside an allowed enum.
It does not prove that the model read the source correctly. A schema-valid price can still be the wrong price, and a schema-valid incident status can still be stale. Treat validation as a gate between model output and downstream automation—not as a substitute for source checks, human review, or business rules.
The useful pipeline is:
- Provide a focused prompt and source input.
- Ask for a small object with a defined schema.
- Reject outputs that fail validation.
- Apply deterministic checks and normalization.
- Only then send, store, or trigger another action.
Where OpenClaw Structured Extraction Fits
OpenClaw has more than one way to work with structured data, so start by choosing the surface that matches the job.
Use llm-task for a single typed transformation
The documented llm-task tool is an optional plugin that runs one JSON-only LLM call. It accepts a prompt, optional input payload, and optional JSON Schema. This is a good fit for turning an email, incident payload, document excerpt, or agent-generated summary into a predictable object.
Use browser extraction for page monitoring
If your input is a live web page, the browser workflow can extract selected fields rather than comparing a whole rendered page. That is the pattern used in our OpenClaw browser monitoring guide: reduce a dynamic page to stable values such as a price, availability flag, or headline before deciding whether something changed.
Use webhooks for delivery, not for schema design
A webhook can start an agent run when another system emits an event, but it does not remove the need to validate the result. Combine this guide with our OpenClaw webhooks guide when an external service should trigger the extraction.
Step 1: Enable and Allow the Optional Tool
The official documentation shows llm-task enabled through the plugin configuration and added to the allowed tools. A minimal JSON configuration looks like this:
{
plugins: {
entries: {
"llm-task": {
enabled: true
}
}
},
tools: {
alsoAllow: ["llm-task"]
}
}
alsoAllow adds the tool without replacing the active tool profile. If you intentionally use a restrictive allowlist, configure the tool through that policy instead.
The same OpenClaw documentation describes an optional llm block for choosing defaults and restricting completion models. Keep that authorization boundary narrow. If a workflow only needs one approved model, do not widen the allowed model list just to make experimentation convenient. Run the configuration through your normal OpenClaw validation and restart/reload procedure for the version you operate.
Before building the workflow, confirm three things:
- the plugin is enabled;
- the active agent is allowed to call
llm-task; - the resolved model and credentials are permitted by the host configuration.
A missing tool and a rejected model are configuration problems, not prompt problems.
Step 2: Design the Smallest Useful Schema
Start with the downstream decision, then work backward to the fields it needs. A small schema is easier to validate, review, and migrate than a transcription of the entire source.
For an incident triage object, an illustrative schema might be:
{
"type": "object",
"additionalProperties": false,
"properties": {
"severity": {
"type": "string",
"enum": ["low", "medium", "high", "critical"]
},
"summary": {
"type": "string",
"minLength": 1
},
"needsHuman": {
"type": "boolean"
},
"nextSteps": {
"type": "array",
"items": { "type": "string" },
"maxItems": 5
}
},
"required": ["severity", "summary", "needsHuman", "nextSteps"]
}
Three design choices do most of the reliability work:
- Require fields that downstream code always reads. Optionality should be deliberate, not a side effect of a hurried prompt.
- Constrain values when the domain is finite. An enum is safer than asking every consumer to interpret spelling variations such as
urgent,critical, andsev-1. - Reject surprise fields when appropriate.
additionalProperties: falsehelps expose prompt drift, although you should allow extra fields when forward compatibility is more important than strictness.
Do not put prose instructions inside the schema. The schema describes the result; the prompt explains how to produce it.
Step 3: Pair the Schema with a Focused Call
The tool reference lists prompt as required and input as an optional payload serialized into the prompt. Keep the input explicit and keep the instruction specific about uncertainty.
An illustrative call shape is:
{
"prompt": "Classify this incident. Use only the supplied event. If severity is unclear, choose medium and set needsHuman to true. Return only the fields described by the schema.",
"input": {
"service": "checkout-api",
"event": "Five-minute error rate crossed the alert threshold after a deployment."
},
"schema": {
"type": "object",
"additionalProperties": false,
"properties": {
"severity": { "type": "string", "enum": ["low", "medium", "high", "critical"] },
"summary": { "type": "string", "minLength": 1 },
"needsHuman": { "type": "boolean" },
"nextSteps": { "type": "array", "items": { "type": "string" }, "maxItems": 5 }
},
"required": ["severity", "summary", "needsHuman", "nextSteps"]
},
"maxTokens": 500,
"timeoutMs": 30000
}
The exact invocation depends on the OpenClaw surface calling the tool, but the contract is the important part: prompt, input, and schema travel together. The tool documentation describes maxTokens as a best-effort output cap and timeoutMs as the run timeout, with a documented default timeout of 30,000 milliseconds.
Use a prompt that says what to do when evidence is missing. “Never guess” is useful, but a typed fallback such as needsHuman: true is more actionable. Also tell the model what source it may use; otherwise an agent may blend remembered context into an extraction that should be based only on the supplied event.
Step 4: Validate Beyond the Schema
Schema validation is the first gate, not the last. After OpenClaw returns an object:
- verify identifiers against the original event;
- normalize dates and units in deterministic code;
- enforce limits such as maximum alert length;
- check that URLs belong to an expected host before linking them;
- route uncertain results to a human instead of an irreversible action;
- log the schema version with the result.
If the result fails validation, preserve the raw input and error details for debugging, but do not silently coerce a malformed object into a successful event. A retry can help with transient model output, but repeated failure should be visible and bounded.
For webhook-driven workflows, include an event ID in your input and deduplicate it before sending notifications. Our OpenClaw webhooks guide covers authentication, isolated runs, and retry-aware delivery. For scheduled jobs, the OpenClaw cron jobs guide is the better starting point.
A Browser-Monitoring Pattern That Avoids False Alerts
Structured extraction is especially useful when monitoring a page. Do not compare the whole DOM if the question is “Is the product available, and what is the current price?” Extract only those fields:
{
"type": "object",
"additionalProperties": false,
"properties": {
"available": { "type": "boolean" },
"price": { "type": ["number", "null"] },
"currency": { "type": ["string", "null"] }
},
"required": ["available", "price", "currency"]
}
Then compare the normalized object with the previous result. Ignore timestamps, rotating recommendations, and session-specific labels unless they are part of the question. If a page becomes unreadable or the extraction fails, treat that as an error state rather than a meaningful product change.
This same “reduce, validate, compare” loop works for release notes, support queues, public status pages, and dashboards. The schema gives your comparison code stable names and types; it does not decide whether the change matters.
Common Failure Modes
The tool is unavailable
Check the plugin entry, tool policy, and model authorization first. The official docs describe llm-task as optional, so an agent that cannot see it may simply be using a configuration where the plugin is disabled or not allowed.
The model returns valid JSON but validation fails
Look for missing required fields, enum spelling, numeric strings, extra properties, or an array that contains an object instead of a string. Tighten the prompt only after reading the validation error. If the source genuinely lacks a value, change the schema to represent uncertainty explicitly rather than forcing a fabricated default.
Validation passes but the result is wrong
Add source-grounding instructions, preserve the input, and require a human-review flag for ambiguous cases. Consider extracting evidence alongside the conclusion when the workflow can support it, then validate that evidence is actually present in the source.
Browser alerts fire on every run
Your schema is probably capturing unstable fields. Reduce it to the smallest meaningful object, normalize numbers and whitespace, and separate extraction failure from a real change. Our browser automation guide covers the underlying managed-browser workflow.
JSON Schema Reliability Checklist
Before connecting the result to a real action, confirm:
- the schema has a clear owner and version;
- required fields map to actual downstream decisions;
- finite values use enums or equivalent constraints;
- input is bounded and treated as untrusted data;
- output length, arrays, and URLs have limits;
- invalid results fail closed and are observable;
- retries are bounded and event IDs are deduplicated;
- a human path exists for ambiguity;
- the model/tool permission is no broader than necessary;
- the production consumer validates again at its boundary.
FAQ
Does JSON Schema make OpenClaw output factual?
No. It validates structure and constraints. The source can be incomplete, and the model can still misunderstand it. Add source checks and a review path for consequential decisions.
Do I need the llm-task plugin for every structured result?
No. It is the documented option for a single JSON-only LLM task with optional schema validation. Browser workflows have their own structured-extraction pattern, and ordinary application code may validate data produced elsewhere.
Should every field be required?
Every field needed by the next step should be required. Fields that are genuinely unavailable should be nullable or represented with an explicit uncertainty flag. Do not make a field optional merely to hide inconsistent output.
How much schema should I write?
Enough to express the downstream contract, no more. Small objects are easier to review and less likely to capture unstable details. Add fields when a real consumer needs them.
Can I use the result to trigger an irreversible action?
Only with additional safeguards. Validate the object, verify it against the source, deduplicate the event, apply deterministic policy, and require human approval for high-impact actions.
Sources
- OpenClaw: LLM task — tool parameters, JSON Schema validation, enablement, and model authorization.
- OpenClaw: LLM Task plugin — plugin distribution reference.
- OpenClaw: TypeBox — schema-driven runtime validation and JSON Schema export.
- OpenClaw: PDF tool — related typed document-processing behavior and provider-dependent fallbacks.
- OpenClaw: OpenClaw overview — Gateway and agent architecture context.
Sources accessed August 2, 2026.




Comments
Loading comments…