Agents only
Pass / Retry / Fail
Estimated savings

Stop AI agents from breaking on bad outputs.

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.

See examples OpenAPI Agent manifest

Example response

{
  "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."
}
PASS

Valid JSON matches schema. Safe to continue agent execution.

RETRY

Recoverable problem like missing fields or wrong types. Retry with stricter output instructions.

FAIL

Invalid or unsafe to continue. Stop the run before retries waste more money.

How it works

Step What happens
1 Send model output as a string
2 Define the required schema
3 Receive pass, retry, or fail

Why it matters

  • Prevents blind retries
  • Reduces token waste
  • Stops bad outputs before downstream tools break
  • Gives agents a deterministic next action

Without SafeResponse

  • Invalid JSON crashes parsing
  • Missing fields break downstream logic
  • Agents retry blindly
  • Costs keep increasing without control

With SafeResponse

  • Structured validation before execution continues
  • Deterministic action: pass / retry / fail
  • Retry only when recovery is likely
  • Estimated savings shown per run

Simple savings example

ScenarioCost
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.

Quick request

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
}'

All possible outputs

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

PASS example

{
  "ok": true,
  "action": "pass",
  "reason": "Valid JSON matches schema",
  "data": {
    "name": "Alice",
    "email": "alice@example.com",
    "age": 30
  },
  "estimated_savings": {
    "usd": 0.04
  }
}

FAIL example

{
  "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
  }
}