# 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.

Source: https://opendecisio.com/docs/use-cases/gatekeeper/

decisio names the rule a command falls under; your policy maps the rule to an action, and only a [certified answer](https://opendecisio.com/docs/glossary/#certified-answer) acts on its own:

 

[Figure: The model judges the input; your code chooses the action. Input: A shell command. Question: Which of the team's rules covers this shell command?. Typed answer: A policy-rule key and probabilities. Your code: Map the rule to allow, block or ask; review uncertified answers..]

 

## TL;DR

 

Save the [complete caller](https://opendecisio.com/examples/recipes/gatekeeper.py) 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](https://opendecisio.com/docs/glossary/#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/ &#x26;&#x26; npm run build"))
```

 Output

```
ask
```

 

## Is it a good fit?

 

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.

 

## 1 Write the question

 

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.

 

## 2 Teach it and certify it

 

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](https://opendecisio.com/docs/glossary/#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](https://opendecisio.com/examples/recipes/gatekeeper-register.py) beside the labels file and run it with Python. Registration replaces a [task](https://opendecisio.com/docs/glossary/#task) of the same id. Check the returned certificate: a `null` [threshold](https://opendecisio.com/docs/glossary/#threshold) means no answer can be certified.

 

[Certify answers](https://opendecisio.com/docs/tasks/certify/#2-teach-the-task-with-a-certificate) runs this call on a server, with its answer.

 

## 3 Route on the certificate

 

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](https://opendecisio.com/docs/tasks/drift/)).

 

## What it did

 

- **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.

 

 

## Limits

 

- An HTTP error, timeout or invalid response goes to the review path, like an uncertified answer ([Handle review and service failures](https://opendecisio.com/docs/use-cases/#handle-review-and-service-failures)).
- Keep the question and options stable after registration, and certify again after changing the task or [serving setup](https://opendecisio.com/docs/glossary/#serving-setup) ([Keep a certificate valid](https://opendecisio.com/docs/production/#keep-a-certificate-valid)).

 

## What next

 

- [Certify answers](https://opendecisio.com/docs/tasks/certify/): the promise, and how to choose the [error target](https://opendecisio.com/docs/glossary/#error-target).
- [Certified answers on real tasks](https://opendecisio.com/demos/teach-and-certify/): the gatekeeper’s rules, its results and its [drift](https://opendecisio.com/docs/glossary/#drift) test.
- [Use cases](https://opendecisio.com/docs/use-cases/): the other recipes.
