Skip to contents

check(call, ctx) sees every tool call before it runs and returns NULL (no opinion) or list(decision = "allow" | "deny" | "ask" | "ask_human" | "modify", reason, input). Decisions combine as deny > ask_human > ask > modify > allow; only a person answers an ask_human, never a hook; a policy that errors denies. Keep checks under 10 ms.

Usage

gptr_policy(name, check, description = NULL)

Arguments

name

Policy name.

check

function(call, ctx).

description

One line for listings.

Value

A spec of class c("gptr_policy", "gptr_spec").

Examples

gptr_policy("no_installs", check = function(call, ctx) {
  if (identical(call$name, "r") && grepl("install.packages", call$input$code, fixed = TRUE)) {
    list(decision = "deny", reason = "installs are not allowed here")
  } else {
    NULL
  }
})
#> <gptr_policy no_installs>
#>   check: <fn>
#>   api_version: 1.0
#>   order: 500