SafeResponse validates model output before your workflow continues. Send output plus an expected schema, and get a deterministic action: pass, retry, or fail.
Catch invalid JSON, missing fields, wrong types, empty responses, and oversized payloads before they waste retries and downstream calls.
{
"ok": false,
"request_id": "sr_1d9c92706b95",
"action": "fail",
"reason": "Invalid JSON: Syntax error",
"retry_prompt": "Return ONLY valid JSON matching the required schema. No prose, no markdown, no code fences.",
"estimated_savings": {
"usd": 0.04,
"formula": "$0.0200 × 2 prevented retries"
},
"usage_note": "Stop run or regenerate with stricter output instructions."
}
Valid JSON matches schema. Safe to continue agent execution.
Recoverable problem like missing fields or wrong types. Retry with stricter output instructions.
Invalid or unsafe to continue. Stop the run before retries waste more money.
| Step | What happens |
|---|---|
| 1 | Send model output as a string |
| 2 | Define the required schema |
| 3 | Receive pass, retry, or fail |
| Scenario | Cost |
|---|---|
| Bad output + 2 blind retries at $0.02 each | $0.06 |
| Bad output + SafeResponse decision first | $0.02 + validation |
| Estimated retries prevented | $0.04 saved |
Actual savings depend on your model pricing and retry behavior.
curl -X POST https://saferesponse.ai/api/validate.php?src=docs \
-H "Content-Type: application/json" \
-d '{
"response":"{\"name\":\"Alice\",\"email\":\"alice@example.com\",\"age\":30}",
"schema":{
"required":{
"name":"string",
"email":"string",
"age":"integer"
}
},
"cost_per_llm_call":0.02,
"assumed_blind_retries":2
}'
| Action | When it appears | Meaning |
|---|---|---|
| pass | JSON parses and matches schema | Continue execution |
| retry | Recoverable structure issue | Retry once with stricter instructions |
| fail | Invalid JSON, empty output, oversized payload, or unsafe to continue | Stop run and escalate |
{
"ok": true,
"action": "pass",
"reason": "Valid JSON matches schema",
"data": {
"name": "Alice",
"email": "alice@example.com",
"age": 30
},
"estimated_savings": {
"usd": 0.04
}
}
{
"ok": false,
"action": "fail",
"reason": "Invalid JSON: Syntax error",
"retry_prompt": "Return ONLY valid JSON matching the required schema. No prose, no markdown, no code fences.",
"estimated_savings": {
"usd": 0.04
}
}