Skip to main content

Tool registry and tool policies

Every time a request offers a tool in its tools list, a model answers with a tool call, or an MCP client calls a tool through the gateway, the gateway writes the tool's name into a registry together with who was using it. That gives you one list of every tool in use across your teams, whether it comes from an MCP server or from a tool a developer defined in a request. Each tool carries two policies. The input policy says whether the tool may run at all, and whether it may run after untrusted tool output has entered the conversation. The output policy says whether the tool's results are trusted. The tool_policy guardrail enforces both, so a prompt injection that arrives through one tool's output cannot drive a sensitive tool a moment later.

The Admin UI shows the registry on the Tool Policies page, described in the Tool Policies page. This page covers the API and the policy model.

A real-world scenario​

A support agent reads tickets with jira-search_issues and can create issues with jira-create_issue. A ticket contains text that tells the model to open twenty issues. The admin has set jira-search_issues to the output policy untrusted and jira-create_issue to the input policy trusted. When the model tries to create issues after reading that ticket, the guardrail blocks the call because untrusted output is in the conversation, the request fails with a clear message, and the attempt appears in the logs. For the interns' team the admin blocks jira-create_issue outright, without changing it for anyone else.

Policies​

PolicyValueMeaning
InputuntrustedThe tool accepts any input, including data from untrusted tool outputs. Every newly discovered tool starts here.
InputtrustedThe tool requires trusted input. The call is blocked when the conversation contains output from any tool whose output policy is untrusted.
InputblockedThe tool is prohibited. Any attempt to call it is rejected.
OutputuntrustedThe tool's output may carry unsafe content such as prompt injection. Downstream tools with the input policy trusted are blocked. The default.
OutputtrustedThe tool's output is treated as safe and never triggers a trust chain block.

A block for one team or key is stored on that team's or key's object permission as a blocked tool, so it applies on top of the global policy and only to requests made through that team or key.

Turn enforcement on​

Discovery is always on. Enforcement needs the tool_policy guardrail in config.yaml. It runs before the call to refuse blocked tools in the request, during and after the call to check the trust chain on the tool calls the model makes.

guardrails:
- guardrail_name: tool_policy
spanway_params:
guardrail: tool_policy
mode: [pre_call, post_call]
default_on: true
  1. Add the guardrail to config.yaml and restart the gateway, or create it with POST /guardrails and "guardrail": "tool_policy". The Admin UI's Add Provider Guardrail form does not offer this type.
  2. Send a chat completion with tools through the gateway. Within a moment the tool appears on Tool Policies with the team, key, user and user agent of that request.

The guardrail reads policies from an in-memory copy that each gateway loads from the database at startup and refreshes on a timer. Until that first load has worked, the guardrail refuses every request that carries tools with 503 Tool policies not loaded instead of letting blocked tools through, which happens when the database is unreachable at startup or general_settings.supported_db_objects leaves out tools. A policy change applies at once on the gateway that took it and on the other gateways at their next sync.

You can set a policy for a tool before any model has used it, for example to block a tool in advance. The gateway then creates the tool's row with a call count of 0.

Set a tool's policy​

  1. In the Admin UI, open Tool Policies. New tools discovered today are listed in the Needs Review banner. Click Review on one to jump to its row.

  2. In the row, change Input Policy or Output Policy with the dropdown. The change saves at once.

  3. Or set it with the API. input_policy and output_policy are both optional, at least one is required:

    curl -X POST http://localhost:4000/v1/tool/policy \
    -H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json" \
    -d '{"tool_name": "jira-create_issue", "input_policy": "trusted"}'

    Expected result:

    {"tool_name": "jira-create_issue", "input_policy": "trusted", "output_policy": "untrusted", "updated": true}
  4. From now on a request that calls jira-create_issue after an untrusted tool's output is in the conversation fails with status 400 and Violated tool policy. Every change writes an audit row on the tool table when audit logging is on, with the policy before and after. A tool that had no row yet is recorded as created.

Block a tool for one team or key​

  1. Open Tool Policies, click the tool name and scroll to Block for team or key. Choose Team or Key, pick the team or key and click Block for team or Block for key.

  2. Or send the same policy request with team_id or key_hash, never both. key_hash accepts the hashed key or the raw sk- key, and the gateway hashes a raw key at once, so the answer and the audit row only ever show the hash. output_policy applies to every caller and is refused with a scope. key_alias in the body is ignored:

    curl -X POST http://localhost:4000/v1/tool/policy \
    -H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json" \
    -d '{"tool_name": "jira-create_issue", "input_policy": "blocked", "team_id": "interns"}'

    Expected result:

    {"tool_name": "jira-create_issue", "input_policy": "blocked", "output_policy": null, "updated": true, "team_id": "interns", "key_hash": null}

    The audit row has the action blocked, with "blocked": false before and "blocked": true after.

  3. The detail view lists the block under Blocked for team or key. Remove lifts it, as does the API. A key goes in the URL as its hash only, because URLs end up in access logs, and a raw sk- key is refused:

    curl -X DELETE "http://localhost:4000/v1/tool/jira-create_issue/overrides?team_id=interns" \
    -H "Authorization: Bearer $SPANWAY_MASTER_KEY"
    {"deleted": true, "tool_name": "jira-create_issue"}

Sending input_policy other than blocked with a team_id or key_hash removes the block for that scope instead of adding one, and answers 404 when there is no block to remove. Both ways of lifting a block write an unblocked audit row.

Delete a tool​

Deleting a tool takes it off the list, for example the tools of an MCP server you have removed, and forgets which key and app first used it. If a model calls the tool again later, it is registered again with the default untrusted policy. That is why a tool whose input policy is blocked cannot be deleted: it would come back unblocked. Team and key blocks on the tool are kept.

  1. Open Tool Policies and click the tool name.

  2. Click Delete Tool at the top right and confirm with Delete. The button is greyed out for a blocked tool, with a note saying why.

  3. Or call the API with a proxy admin key:

    curl -X DELETE http://localhost:4000/v1/tool/old_tool \
    -H "Authorization: Bearer $SPANWAY_MASTER_KEY"

    Expected result:

    {"deleted": true, "tool_name": "old_tool"}

The delete writes a deleted audit row on the tool table with the tool's origin, policies, call count and team before the delete.

Follow a tool's calls and spend​

GET /v1/tool/list returns every discovered tool with its policies, call count and the request that discovered it, with ?input_policy=blocked as a filter. The call count goes up by one each time a gateway writes a batch of discovered tools that includes the tool, so it shows how often the tool turns up, not an exact number of calls. GET /v1/tool/{tool_name}/detail adds the team and key blocks, and GET /v1/tool/{tool_name}/logs pages through the requests that called it, newest first, with page, page_size, start_date and end_date as YYYY-MM-DD, which is the exact call count. Because the logs show the first 200 characters of each prompt, a page that carries prompt text writes an exported audit row naming the request ids. GET /v1/tool/spend gives proxy admins the spend attributed to each tool over a date range, which the Cost Optimization page charts. A request that called several tools counts its whole spend towards each of them.

curl "http://localhost:4000/v1/tool/jira-create_issue/logs?page=1&page_size=20" \
-H "Authorization: Bearer $SPANWAY_MASTER_KEY"
{
"logs": [{"id": "chatcmpl-9f2a6c1e", "timestamp": "2026-11-21T08:30:00+00:00", "model": "claude-sonnet-5-5", "spend": 0.0042, "total_tokens": 1830, "input_snippet": "Create a Jira issue for the login outage..."}],
"total": 1,
"page": 1,
"page_size": 20
}

Routes​

MethodPathSummary
GET/v1/tool/listList the discovered tools and their policies
POST/v1/tool/policySet a tool's policy, globally or for one team or key
GET/v1/tool/policy/optionsList the input and output policy values
GET/v1/tool/spendSpend attributed to each tool
GET/v1/tool/{tool_name}Get one tool
DELETE/v1/tool/{tool_name}Delete a tool from the registry
GET/v1/tool/{tool_name}/detailGet a tool with its team and key blocks
GET/v1/tool/{tool_name}/logsList the requests that called a tool
DELETE/v1/tool/{tool_name}/overridesRemove a team or key block on a tool

Errors​

StatusWhereMeaningFix
400 {"error": "Violated tool policy", "blocked_tools": ["jira-create_issue"], "message": "Tool(s) ['jira-create_issue'] are blocked by policy."}Any model requestThe request names a tool whose input policy is blocked, globally or for the caller's team or key.Pick another tool, or lift the block.
400 {"error": "Violated tool policy", "blocked_tools": [...], "untrusted_sources": [...], "message": "... requires trusted input but conversation contains untrusted output from ..."}Any model requestA trusted input tool was called after an untrusted output tool.Mark the source tool's output trusted if its results are safe, or keep the block.
503 {"error": "Tool policies not loaded", ...}Any model request with toolsThe guardrail is on but this gateway has not loaded tool policies from the database yet.Check the database connection and that general_settings.supported_db_objects includes tools.
400 At least one of input_policy or output_policy must be providedPOST /v1/tool/policyThe body sets neither policy.Send at least one.
400 Provide either team_id or key_hash, not bothPOST /v1/tool/policy, DELETE .../overridesBoth scopes were sent.Send one.
400 output_policy applies to every caller, so send it without team_id or key_hashPOST /v1/tool/policyA scoped request tried to set the output policy.Send the output policy without a scope.
400 At least one of team_id or key_hash is required to identify the overrideDELETE .../overridesNeither scope was sent.Send one.
400 Send the hashed key in key_hash, not the raw sk- key, because URLs are written to access logsDELETE .../overridesThe query string carried a raw key.Send the key's hash from Virtual Keys, and rotate the key if the URL was logged.
400 Invalid date format: <value>. Expected: 'YYYY-MM-DD'GET /v1/tool/spend, GET /v1/tool/{tool_name}/logsA date is not YYYY-MM-DD.Send dates like 2026-11-22.
401 Authentication Error, Only proxy admin can be used ...Every routeThe key is not an admin key. Admin viewers may read but not change.Use an admin key.
403 Only proxy admin roles can view tool spend across the deploymentGET /v1/tool/spendThe key is not a proxy admin or admin viewer key.Use an admin key.
404 Tool 'jira-create_issue' not foundGET /v1/tool/{tool_name} and /detailThe gateway has not seen that tool yet.Check the name on Tool Policies. Names of MCP tools carry the server prefix.
404 Tool 'old_tool' not foundDELETE /v1/tool/{tool_name}No tool has that name.Check the name on Tool Policies.
409 Tool 'old_tool' is blocked. Change its input policy before deleting it, so it cannot come back unblockedDELETE /v1/tool/{tool_name}The tool is blocked for everyone, and a deleted tool returns with the default untrusted policy.Keep the tool, or set its input policy to untrusted or trusted first.
404 Key or team not found for the given identifierPOST /v1/tool/policy, DELETE .../overridesteam_id or key_hash matches nothing.Copy the id from Teams or the hash from Virtual Keys.
404 No override found for tool '...' with the given scopePOST /v1/tool/policy lifting a block, DELETE .../overridesThere is no block for that team or key.Nothing to remove.
500 DB not connected. This endpoint needs a database; set DATABASE_URL ...Every routeThe registry lives in the database and the gateway runs without one.Set DATABASE_URL.
500 Failed to update policy for tool '...', Failed to update policy override for tool '...'POST /v1/tool/policyThe database write failed.Check the database and retry.

Logs​

LevelLineMeaningAction
WARNINGToolPolicyGuardrail: blocking tool(s) [...] (input_policy=blocked)A request that lists or calls a blocked tool was refused.None, unless the block is a mistake.
WARNINGToolPolicyGuardrail: trust chain violation ...A trusted tool was asked to act on untrusted tool output.Review the two tools' policies.
WARNINGToolPolicyGuardrail: refusing tool(s) [...] because tool policies are not loaded from the database yetThe guardrail refused tool requests until the first policy load.Check the database and supported_db_objects.
INFOToolPolicyRegistry: synced <n> tool policies and <m> object permissions from DBThis gateway reloaded its policies.None.
WARNINGTool policy saved, but reloading the in-memory registry failed, so this gateway applies it at the next periodic sync: ...The change is stored and audited but not yet live on this gateway.Check the database.
ERRORtool_registry_writer <operation> error: ...A registry read or write failed.Check the database.

The log reference and the error reference list the same lines.