Skip to content

DocsExamples

5 min read · updated

Coding-agent gatekeeper

Decide allow, ask or block for each shell command a coding agent proposes, by your team's own rules, and ask a person only when decisio is not sure.

decisio names the rule a command falls under; your policy maps the rule to an action, and only a certified answer acts on its own:

Figure · How to use it

The model judges the input; your code chooses the action.

  1. InputA shell command
  2. QuestionWhich of the team's rules covers this shell command?
  3. Typed answerA policy-rule key and probabilities
  4. Your codeMap the rule to allow, block or ask; review uncertified answers.

The answer is under answers.rule. Check the certificate required by your application before automating the action.

Source: this recipe’s question and application policy. No model result is illustrated here.

Save the complete caller as gatekeeper.py and run it with Python 3.12 or later. Set DECISIO_BASE_URL to your server, or leave the local default. Until you register and certify this question, the caller sends answers to review.

python
import json
import os
import urllib.error
import urllib.request
POLICY = {
"inspect": "allow",
"git_read": "allow",
"git_local_write": "allow",
"git_discard": "ask",
"git_push": "ask",
"git_push_force_or_protected": "block",
"test_build_lint": "allow",
"run_scripts": "ask",
"install_packages": "ask",
"edit_workspace": "allow",
"delete_in_workspace": "ask",
"outside_workspace": "block",
"secrets": "block",
"network_and_cloud": "ask",
"remote_code_or_privilege": "block",
"other": "ask",
}
QUESTION = {
"type": "choice",
"instructions": "Which of the team's rules covers this shell command?",
"criteria": {
"inspect": None,
"git_read": None,
"git_local_write": None,
"git_discard": None,
"git_push": None,
"git_push_force_or_protected": None,
"test_build_lint": None,
"run_scripts": None,
"install_packages": None,
"edit_workspace": None,
"delete_in_workspace": None,
"outside_workspace": None,
"secrets": None,
"network_and_cloud": None,
"remote_code_or_privilege": None,
"other": None
}
}
BASE_URL = os.environ.get("DECISIO_BASE_URL", "http://127.0.0.1:8000").rstrip("/")
TIMEOUT = 15
REVIEW = "ask"
def route(text):
request = urllib.request.Request(
BASE_URL + "/v1/systemone",
data=json.dumps({"state": text, "questions": {"rule": QUESTION}}).encode(),
headers={"Content-Type": "application/json"},
)
try:
with urllib.request.urlopen(request, timeout=TIMEOUT) as response:
answer = json.load(response)["answers"]["rule"]
if not isinstance(answer, dict) or answer.get("type") != QUESTION["type"]:
return REVIEW
if not (answer.get("choice") in QUESTION["criteria"]):
return REVIEW
# A gold certificate is about correctness; agreement alone is insufficient.
if (answer.get("certified") is True
and answer.get("certificate_kind") == "gold"
and isinstance(answer.get("certificate"), str)
and answer["certificate"]):
return POLICY[answer["choice"]]
return "ask"
except (urllib.error.URLError, TimeoutError, OSError, ValueError, KeyError, TypeError):
return REVIEW
if __name__ == "__main__":
print(route("rm -rf build/ && npm run build"))
Output
ask

Good fit

  • Written rules for what an agent may do, each with an action.
  • Labelled commands for every rule, to teach and certify from.
  • A catch-all rule that asks, for the commands no rule names.

Not a good fit

  • A policy that is not written down: decisio learns rules from examples, it does not invent them.
  • Commands whose risk depends on things the text does not show, such as what a script does inside.

One choice question: which rule covers this command. Keep the policy beside it, so the action is yours, not the model’s, and changing an action needs no teaching.

Teach the question from labelled commands and certify it at 5%.

Send at least 320 labelled commands. The server holds back half to certify, and a 5% certificate needs 59 of those; the other half teaches, at 10 per option for this question's 16 options. More examples certify a larger share.

Prepare gatekeeper-labels.jsonl with one JSON object per line, containing state and answer. Use real inputs and labels chosen by a person; each answer is one of the question’s option keys. The code below builds complete requests using the same question as the caller.

python
import json
import os
import urllib.request
QUESTION = {
"type": "choice",
"instructions": "Which of the team's rules covers this shell command?",
"criteria": {
"inspect": None,
"git_read": None,
"git_local_write": None,
"git_discard": None,
"git_push": None,
"git_push_force_or_protected": None,
"test_build_lint": None,
"run_scripts": None,
"install_packages": None,
"edit_workspace": None,
"delete_in_workspace": None,
"outside_workspace": None,
"secrets": None,
"network_and_cloud": None,
"remote_code_or_privilege": None,
"other": None
}
}
# One JSON object per line: state and the answer chosen by a person.
with open("gatekeeper-labels.jsonl", encoding="utf-8") as source:
rows = [json.loads(line) for line in source if line.strip()]
examples = [
{"request": {"state": row["state"], "questions": {"rule": QUESTION}},
"answer": row["answer"]}
for row in rows
]
body = {"id": "gatekeeper", "examples": examples, "certify": {"alpha": 0.05}}
base_url = os.environ.get("DECISIO_BASE_URL", "http://127.0.0.1:8000").rstrip("/")
request = urllib.request.Request(
base_url + "/v1/tasks", data=json.dumps(body).encode(),
headers={"Content-Type": "application/json"},
)
# Registration reads all your examples; allow more time than an ordinary decision.
with urllib.request.urlopen(request, timeout=300) as response:
record = json.load(response)
print(json.dumps(record.get("certificate"), indent=2))

Needs the reader’s own human-labelled JSONL file.

Save the registration script beside the labels file and run it with Python. Registration replaces a task of the same id. Check the returned certificate: a null threshold means no answer can be certified.

Certify answers runs this call on a server, with its answer.

The caller acts only when certified is true and certificate_kind is gold, with a certificate id. A learned table’s agreement certificate measures agreement with the model, so it goes to review in this recipe.

  • A certified answer takes the rule’s action: allow, ask or block.
  • Anything else asks a person.
  • In the measured run, a kind of command that no rule named was never certified, so it went to a person (Watch for drift).
  • 34% to 40% of a coding agent's shell commands decided on their own at a 5% error target, with the wrong action on 1.6% to 2.3% of them: 16 rules, Gemma 4 12B on a Mac (the 6-bit MLX conversion), taught with 20 labelled commands per rule, 3 draws, 1,481 test commands.
  • When a kind of command no rule names rose to 30% of the traffic, none of its 184 commands was certified.

Measured on decisio 0.14.0, Gemma 4 12B on a Mac, 2026-10-17 and 2026-10-18.