LLM
Validate + coerce to schema API
Validates a (possibly stringified) LLM value against a minimal JSON-Schema and coerces loose types — numeric strings to numbers, yes/no/1 to booleans, integer rounding, min/max clamping, applied defaults — returning the cleaned value, every coercion, and any remaining validation errors. Answers 'how do I force model output to match my schema?', 'how do I clean up loosely-typed JSON from an LLM?'.
Price$0.05per request
MethodPOST
Route/v1/llm/schema-coerce
StatusLive
MIME typeapplication/json
Rate limit120/minute
Cache0s public
llmjson-schemavalidatecoercestructured-outputfunction-callingtypesagent
API URL
Integration docshttps://x402.hexl.dev/v1/llm/schema-coerceExample request
{
"data": "{\"age\":\"30\",\"active\":\"yes\"}",
"schema": {
"type": "object",
"properties": {
"age": {
"type": "integer"
},
"active": {
"type": "boolean"
},
"role": {
"type": "string",
"default": "user"
}
},
"required": [
"age"
]
}
}Example response
{
"ok": true,
"valid": true,
"coerced": {
"age": 30,
"active": true,
"role": "user"
},
"errors": [],
"coercions": [
"$: parsed-json-string",
"$.age: string->number",
"$.active: string->boolean",
"$.role: applied-default"
]
}Input schema
{
"type": "object",
"required": [
"data",
"schema"
],
"properties": {
"data": {
"description": "The LLM value (object or JSON string) to validate/coerce.",
"examples": [
"{\"age\":\"30\",\"active\":\"yes\"}"
]
},
"schema": {
"type": "object",
"description": "Minimal JSON-Schema with type/properties/required/items/enum/default/minimum/maximum."
}
}
}Output schema
{
"type": "object",
"additionalProperties": true
}