{
  "license": "CC BY 4.0",
  "licenseUrl": "https://creativecommons.org/licenses/by/4.0/",
  "recipe": {
    "slug": "ai-agent-tool-authorization-decisions",
    "title": "Audit AI Agent Tool Authorization Decisions",
    "testedWith": "Apache DataFusion 45.2.0",
    "lastReviewed": "2026-07-30"
  },
  "contract": {
    "tableName": "agent_tool_authorization_decisions",
    "schema": [
      {
        "name": "timestamp_utc",
        "type": "Timestamp",
        "description": "Final policy-decision time in UTC."
      },
      {
        "name": "workflow",
        "type": "Utf8",
        "description": "Versioned, low-cardinality agent workflow."
      },
      {
        "name": "tool_name",
        "type": "Utf8",
        "description": "Approved low-cardinality tool identifier."
      },
      {
        "name": "action_class",
        "type": "Utf8",
        "description": "Controlled class such as read_only or external_state_change."
      },
      {
        "name": "risk_level",
        "type": "Utf8",
        "description": "Reviewed low, medium, or high risk class."
      },
      {
        "name": "decision",
        "type": "Utf8",
        "description": "Allowed, denied, or approval_required."
      },
      {
        "name": "reason_code",
        "type": "Utf8",
        "description": "Controlled policy reason without a free-form model explanation."
      },
      {
        "name": "policy_version",
        "type": "Utf8",
        "description": "Version of the policy contract used for the decision."
      },
      {
        "name": "environment",
        "type": "Utf8",
        "description": "Deployment environment."
      }
    ]
  },
  "query": "SELECT\n  tool_name,\n  risk_level,\n  COUNT(*) AS decisions,\n  SUM(CASE WHEN decision = 'denied' THEN 1 ELSE 0 END) AS denied,\n  SUM(CASE WHEN decision = 'approval_required' THEN 1 ELSE 0 END) AS approval_required,\n  SUM(CASE WHEN decision = 'allowed' THEN 1 ELSE 0 END) AS allowed,\n  100.0 * SUM(CASE WHEN decision = 'denied' THEN 1 ELSE 0 END)\n    / NULLIF(COUNT(*), 0) AS denial_rate_pct\nFROM agent_tool_authorization_decisions\nWHERE timestamp_utc >= now() - INTERVAL '30 days'\n  AND environment = 'production'\nGROUP BY tool_name, risk_level\nORDER BY denied DESC, approval_required DESC, tool_name;",
  "fixtureKind": "reproducible",
  "inputRows": [
    {
      "timestamp_utc": "2026-07-28T18:00:00.000Z",
      "workflow": "support_resolution_v3",
      "tool_name": "database_write",
      "action_class": "external_state_change",
      "risk_level": "high",
      "decision": "denied",
      "reason_code": "policy_scope_denied",
      "policy_version": "agent-policy-12",
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:59:00.000Z",
      "workflow": "support_resolution_v3",
      "tool_name": "database_write",
      "action_class": "external_state_change",
      "risk_level": "high",
      "decision": "denied",
      "reason_code": "policy_scope_denied",
      "policy_version": "agent-policy-12",
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:58:00.000Z",
      "workflow": "support_resolution_v3",
      "tool_name": "database_write",
      "action_class": "external_state_change",
      "risk_level": "high",
      "decision": "approval_required",
      "reason_code": "human_approval_required",
      "policy_version": "agent-policy-12",
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:57:00.000Z",
      "workflow": "support_resolution_v3",
      "tool_name": "database_write",
      "action_class": "external_state_change",
      "risk_level": "high",
      "decision": "allowed",
      "reason_code": "policy_scope_allowed",
      "policy_version": "agent-policy-12",
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:40:00.000Z",
      "workflow": "support_resolution_v3",
      "tool_name": "filesystem_write",
      "action_class": "local_state_change",
      "risk_level": "high",
      "decision": "denied",
      "reason_code": "policy_scope_denied",
      "policy_version": "agent-policy-12",
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:39:00.000Z",
      "workflow": "support_resolution_v3",
      "tool_name": "filesystem_write",
      "action_class": "local_state_change",
      "risk_level": "high",
      "decision": "approval_required",
      "reason_code": "human_approval_required",
      "policy_version": "agent-policy-12",
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:38:00.000Z",
      "workflow": "support_resolution_v3",
      "tool_name": "filesystem_write",
      "action_class": "local_state_change",
      "risk_level": "high",
      "decision": "approval_required",
      "reason_code": "human_approval_required",
      "policy_version": "agent-policy-12",
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:37:00.000Z",
      "workflow": "support_resolution_v3",
      "tool_name": "filesystem_write",
      "action_class": "local_state_change",
      "risk_level": "high",
      "decision": "allowed",
      "reason_code": "policy_scope_allowed",
      "policy_version": "agent-policy-12",
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:20:00.000Z",
      "workflow": "support_resolution_v3",
      "tool_name": "web_search",
      "action_class": "read_only",
      "risk_level": "medium",
      "decision": "allowed",
      "reason_code": "policy_scope_allowed",
      "policy_version": "agent-policy-12",
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:19:00.000Z",
      "workflow": "support_resolution_v3",
      "tool_name": "web_search",
      "action_class": "read_only",
      "risk_level": "medium",
      "decision": "allowed",
      "reason_code": "policy_scope_allowed",
      "policy_version": "agent-policy-12",
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:18:00.000Z",
      "workflow": "support_resolution_v3",
      "tool_name": "web_search",
      "action_class": "read_only",
      "risk_level": "medium",
      "decision": "allowed",
      "reason_code": "policy_scope_allowed",
      "policy_version": "agent-policy-12",
      "environment": "production"
    }
  ],
  "illustrativeInputRows": [
    {
      "timestamp_utc": "2026-07-28T18:00:00.000Z",
      "workflow": "support_resolution_v3",
      "tool_name": "database_write",
      "action_class": "external_state_change",
      "risk_level": "high",
      "decision": "denied",
      "reason_code": "policy_scope_denied",
      "policy_version": "agent-policy-12",
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:59:00.000Z",
      "workflow": "support_resolution_v3",
      "tool_name": "database_write",
      "action_class": "external_state_change",
      "risk_level": "high",
      "decision": "denied",
      "reason_code": "policy_scope_denied",
      "policy_version": "agent-policy-12",
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:58:00.000Z",
      "workflow": "support_resolution_v3",
      "tool_name": "database_write",
      "action_class": "external_state_change",
      "risk_level": "high",
      "decision": "approval_required",
      "reason_code": "human_approval_required",
      "policy_version": "agent-policy-12",
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:57:00.000Z",
      "workflow": "support_resolution_v3",
      "tool_name": "database_write",
      "action_class": "external_state_change",
      "risk_level": "high",
      "decision": "allowed",
      "reason_code": "policy_scope_allowed",
      "policy_version": "agent-policy-12",
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:40:00.000Z",
      "workflow": "support_resolution_v3",
      "tool_name": "filesystem_write",
      "action_class": "local_state_change",
      "risk_level": "high",
      "decision": "denied",
      "reason_code": "policy_scope_denied",
      "policy_version": "agent-policy-12",
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:39:00.000Z",
      "workflow": "support_resolution_v3",
      "tool_name": "filesystem_write",
      "action_class": "local_state_change",
      "risk_level": "high",
      "decision": "approval_required",
      "reason_code": "human_approval_required",
      "policy_version": "agent-policy-12",
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:38:00.000Z",
      "workflow": "support_resolution_v3",
      "tool_name": "filesystem_write",
      "action_class": "local_state_change",
      "risk_level": "high",
      "decision": "approval_required",
      "reason_code": "human_approval_required",
      "policy_version": "agent-policy-12",
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:37:00.000Z",
      "workflow": "support_resolution_v3",
      "tool_name": "filesystem_write",
      "action_class": "local_state_change",
      "risk_level": "high",
      "decision": "allowed",
      "reason_code": "policy_scope_allowed",
      "policy_version": "agent-policy-12",
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:20:00.000Z",
      "workflow": "support_resolution_v3",
      "tool_name": "web_search",
      "action_class": "read_only",
      "risk_level": "medium",
      "decision": "allowed",
      "reason_code": "policy_scope_allowed",
      "policy_version": "agent-policy-12",
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:19:00.000Z",
      "workflow": "support_resolution_v3",
      "tool_name": "web_search",
      "action_class": "read_only",
      "risk_level": "medium",
      "decision": "allowed",
      "reason_code": "policy_scope_allowed",
      "policy_version": "agent-policy-12",
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:18:00.000Z",
      "workflow": "support_resolution_v3",
      "tool_name": "web_search",
      "action_class": "read_only",
      "risk_level": "medium",
      "decision": "allowed",
      "reason_code": "policy_scope_allowed",
      "policy_version": "agent-policy-12",
      "environment": "production"
    }
  ],
  "expectedOutput": {
    "columns": [
      "tool_name",
      "risk_level",
      "decisions",
      "denied",
      "approval_required",
      "allowed",
      "denial_rate_pct"
    ],
    "rows": [
      {
        "tool_name": "database_write",
        "risk_level": "high",
        "decisions": 4,
        "denied": 2,
        "approval_required": 1,
        "allowed": 1,
        "denial_rate_pct": 50
      },
      {
        "tool_name": "filesystem_write",
        "risk_level": "high",
        "decisions": 4,
        "denied": 1,
        "approval_required": 2,
        "allowed": 1,
        "denial_rate_pct": 25
      },
      {
        "tool_name": "web_search",
        "risk_level": "medium",
        "decisions": 3,
        "denied": 0,
        "approval_required": 0,
        "allowed": 3,
        "denial_rate_pct": 0
      }
    ]
  },
  "notes": [
    "The included synthetic input rows generate the expected output when timestamps are shifted into the documented query window.",
    "Run this fixture in the public browser SQL playground; the selected query executes locally with DuckDB-Wasm.",
    "Adapt time windows, thresholds, identities, and business definitions before operational use."
  ]
}