Guard an agent's tool call arguments
Your task
An operations agent can call a restart_service tool. Model output is not trusted, so a guard checks the arguments of every call before the tool sees them. The tool's schema maps each parameter name to {"type": "str" | "int" | "bool", "required": bool}, and an "int" parameter may also carry a "max".
Write check_args(schema, args). Return "ok", or the first problem as "<kind>:<name>". Check the kinds in this order, and if one kind has several offenders, report the name that sorts first in plain string order (by character code, so uppercase before lowercase):
"unknown:<name>": an argument that is not in the schema, even one whose value isNone. Models invent parameters, and the guard must not pass them along."missing:<name>": a required parameter that is absent. An argument whose value isNone(null) counts as absent."type:<name>": a value of the wrong type."str"means a string;"bool"meanstrueorfalse;"int"means a whole number and never a boolean. (In Python,boolis a subclass ofint, soisinstance(True, int)isTrue: check for it.)"limit:<name>": an int below 0, or above its"max"when it has one. The max is inclusive.
Names are case-sensitive. An optional parameter that is absent (or None) is fine.
Examples, with this schema:
{
"service": { "type": "str", "required": true },
"replicas": { "type": "int", "required": false, "max": 10 },
"force": { "type": "bool", "required": false }
}
check_args(schema, {"service": "api", "replicas": 3})returns"ok".check_args(schema, {"service": "api", "replicas": 12, "region": "eu"})returns"unknown:region": unknown arguments are reported before the limit problem.check_args(schema, {"service": "api", "replicas": True})returns"type:replicas".
Examples
check_args(schema: dict, args: dict) -> strExample 1
Input
check_args({"service": {"type": "str", "required": True}, "replicas": {"type": "int", "required": False, "max": 10}, "force": {"type": "bool", "required": False}}, {"service": "api", "replicas": 3})Output
"ok"Example 2
Input
check_args({"service": {"type": "str", "required": True}, "replicas": {"type": "int", "required": False, "max": 10}, "force": {"type": "bool", "required": False}}, {"service": "api", "replicas": 12, "region": "eu"})Output
"unknown:region"Example 3
Input
check_args({"service": {"type": "str", "required": True}, "replicas": {"type": "int", "required": False, "max": 10}, "force": {"type": "bool", "required": False}}, {"service": "api", "replicas": True})Output
"type:replicas"