{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/withhuman-ai/json-schema/withhuman-ai-request-approval-pipeline-preview-schema.json",
  "title": "RequestApprovalPipelinePreview",
  "description": "What the pipeline did with the sample.",
  "x-generated": "2026-11-29",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/withhuman-ai-openapi.yaml#/components/schemas/RequestApprovalPipelinePreview",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "outcome",
    "reason_code",
    "blocks"
  ],
  "properties": {
    "outcome": {
      "type": "string",
      "enum": [
        "approve",
        "deny",
        "human"
      ],
      "description": "The final outcome."
    },
    "reason_code": {
      "type": "string",
      "enum": [
        "block_outcome",
        "block_error",
        "block_timeout",
        "retries_exhausted",
        "invalid_block_output",
        "end_of_pipeline",
        "end_of_branch"
      ],
      "description": "Why the run ended. `block_outcome`: a block decided. `block_error`, `block_timeout`, `retries_exhausted`, `invalid_block_output`: a block failed. `end_of_pipeline`: the request passed every block. `end_of_branch`: the request entered a branch or a delegated pipeline and none of its blocks decided."
    },
    "terminal_block_id": {
      "type": "string",
      "description": "The block that ended the run: for `end_of_branch`, the branch or the delegate. Absent when the request passed every block."
    },
    "blocks": {
      "type": "array",
      "description": "What each block the request reached did, in order, each with the pipeline it belongs to. A branch or delegate appears when its condition is evaluated, and once more with `end_of_branch` when none of the blocks inside decided.",
      "items": {
        "$ref": "#/$defs/RequestApprovalPipelinePreviewBlock"
      }
    },
    "escalation_path": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9._-]{0,62}$",
      "description": "The path a `human` outcome goes to: the ending block's path, else the default of the pipeline the request was in, else the defaults of the pipelines that delegated into it. Absent when the outcome is automatic or no path applies."
    },
    "escalation_path_reason": {
      "type": "string",
      "enum": [
        "block_escalation",
        "pipeline_default",
        "no_escalation"
      ],
      "description": "Where the path came from. `block_escalation`: the ending block named it. `pipeline_default`: a pipeline's default. `no_escalation`: no path applies."
    },
    "escalation_path_pipeline_key": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9._-]{0,62}$",
      "description": "The pipeline whose block or default supplied the path. Absent with `no_escalation`."
    },
    "ask_agent_owner": {
      "type": "boolean",
      "description": "Present when the route asks the agent's owner, with `escalation_path` as the fallback. A preview has no real agent instance, so it names the route, never a person."
    }
  },
  "$defs": {
    "RequestApprovalPipelinePreviewBlock": {
      "type": "object",
      "additionalProperties": false,
      "description": "What one block did in a preview.",
      "required": [
        "block_id",
        "pipeline_key",
        "position",
        "outcome",
        "cost",
        "trace"
      ],
      "properties": {
        "block_id": {
          "type": "string",
          "description": "The block's key."
        },
        "pipeline_key": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9._-]{0,62}$",
          "description": "The pipeline the block belongs to: the previewed document's key, or a delegated pipeline's."
        },
        "position": {
          "type": "integer",
          "minimum": 0,
          "description": "The block's position in the effective pipeline, from 0, counting in document order with each branch or delegate before the blocks it holds."
        },
        "outcome": {
          "type": "string",
          "enum": [
            "next",
            "approve",
            "deny",
            "human",
            "enter"
          ],
          "description": "What the block returned. A branch or delegate returns `enter` when its condition matched and `next` when it did not."
        },
        "reason": {
          "type": "string",
          "description": "The note the block recorded."
        },
        "metadata": {
          "type": "object",
          "additionalProperties": true,
          "description": "The metadata the block returned, if any."
        },
        "cost": {
          "type": "integer",
          "format": "int64",
          "minimum": 0,
          "description": "The cost the block recorded."
        },
        "error_code": {
          "type": "string",
          "description": "Why the block failed, if it did: `invalid_input`, `input_too_large`, `evaluation_error`, `cost_limit_exceeded`, `resource_limit_exceeded`, `timeout`, `invalid_block_output`, `internal_error`, `provider_error`, `endpoint_unreachable`, `endpoint_error`, `endpoint_rejected`, `outcome_not_allowed`, `endpoint_unavailable`, or a code a kind the edition adds reports (the hosted judge's `model_unavailable`)."
        },
        "delivery": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "endpoint_key",
            "endpoint_host",
            "duration_ms"
          ],
          "description": "For webhook blocks. What was called and what came back. Never the bodies, never the secret.",
          "properties": {
            "endpoint_key": {
              "type": "string",
              "pattern": "^[a-z0-9][a-z0-9._-]{0,62}$",
              "description": "The endpoint that was called."
            },
            "endpoint_revision": {
              "type": "integer",
              "format": "int64",
              "minimum": 1,
              "description": "The revision that was delivered to. Absent when the endpoint had no active revision."
            },
            "endpoint_host": {
              "type": "string",
              "description": "The host that was called."
            },
            "http_status": {
              "type": "integer",
              "description": "The HTTP status the endpoint returned."
            },
            "duration_ms": {
              "type": "integer",
              "format": "int64",
              "description": "How long the call took, in milliseconds."
            },
            "reason": {
              "type": "string",
              "description": "The endpoint's own explanation, at most 1,024 characters."
            }
          }
        },
        "trace": {
          "type": "array",
          "description": "How the condition was evaluated, node by node. For condition blocks and branches.",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "node_id",
              "matched",
              "error"
            ],
            "properties": {
              "node_id": {
                "type": "string",
                "format": "uuid",
                "description": "The condition's id."
              },
              "matched": {
                "type": "boolean",
                "description": "Whether the condition held."
              },
              "error": {
                "type": "boolean",
                "description": "Whether evaluating it failed."
              }
            }
          }
        },
        "end_of_branch": {
          "type": "boolean",
          "description": "Present and true on the step that closes a branch the request entered when none of its blocks decided. The outcome is `human`."
        }
      }
    }
  }
}