{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://capxule.ai/schemas/error.json",
  "title": "Error envelope",
  "description": "Every tool error. On MCP it rides structuredContent and content[0].text with isError: true. Walls are beats, never errors.",
  "version": "2026-10-11",
  "for_humans": "https://capxule.com",
  "produced_by": [
    "every tool"
  ],
  "type": "object",
  "properties": {
    "error": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string",
          "enum": [
            "session_expired",
            "session_required",
            "capsule_not_found",
            "turn_conflict",
            "rate_limited",
            "preparing",
            "locale_unavailable",
            "not_available",
            "option_invalid",
            "invalid_arguments",
            "moderation",
            "unavailable",
            "challenge_expired",
            "code_invalid",
            "email_rejected",
            "phone_rejected",
            "delegation_limit",
            "host_policy",
            "authorization_pending",
            "slow_down",
            "pass_expired",
            "payment_pending"
          ]
        },
        "for_human": {
          "type": "string",
          "description": "Say it as given."
        },
        "for_agent": {
          "type": "string",
          "description": "Do it."
        },
        "next": {
          "anyOf": [
            {
              "anyOf": [
                {
                  "type": "object",
                  "properties": {
                    "kind": {
                      "type": "string",
                      "const": "call"
                    },
                    "tool": {
                      "type": "string"
                    },
                    "args": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {}
                    }
                  },
                  "required": [
                    "kind",
                    "tool"
                  ],
                  "additionalProperties": false
                },
                {
                  "type": "object",
                  "properties": {
                    "kind": {
                      "type": "string",
                      "const": "retry"
                    },
                    "then": {
                      "type": "string"
                    },
                    "retry_after_ms": {
                      "type": "number"
                    }
                  },
                  "required": [
                    "kind",
                    "then"
                  ],
                  "additionalProperties": false
                },
                {
                  "type": "object",
                  "properties": {
                    "kind": {
                      "type": "string",
                      "const": "url"
                    },
                    "url": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "kind",
                    "url"
                  ],
                  "additionalProperties": false
                },
                {
                  "type": "object",
                  "properties": {
                    "kind": {
                      "type": "string",
                      "const": "wait"
                    },
                    "retry_after_ms": {
                      "type": "number"
                    }
                  },
                  "required": [
                    "kind",
                    "retry_after_ms"
                  ],
                  "additionalProperties": false
                }
              ]
            },
            {
              "type": "null"
            }
          ]
        },
        "retryable": {
          "type": "boolean"
        },
        "retry_after_ms": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ]
        },
        "doc": {
          "type": "string"
        },
        "alternatives": {
          "description": "Only on capsule_not_found: at most three published cards.",
          "type": "array",
          "items": {
            "type": "object",
            "propertyNames": {
              "type": "string"
            },
            "additionalProperties": {}
          }
        }
      },
      "required": [
        "code",
        "for_human",
        "for_agent",
        "next",
        "retryable",
        "retry_after_ms",
        "doc"
      ],
      "additionalProperties": {}
    }
  },
  "required": [
    "error"
  ],
  "additionalProperties": false
}
