TL;DR
Best practices for implementing LLM access controls and monitoring start with a single source of truth: a permission bitmask. Each bit represents one capability. Forbidden phrases get -inf logits or forced EOS. Unsafe tool calls are blocked before execution. reskSecure implements this at the logits level, inside the model generation loop, so the model can never emit the first token of a disallowed action.
The risk: what goes wrong without this mechanism
Without a permission bitmask, an agent is a black box with root access. A user with read-only intent can ask the model to send an email, and the model will happily generate send_email( because nothing in the generation loop checks capabilities. Prompt-based filters can be jailbroken. Post-generation moderation catches violations after the forbidden content has already been emitted. The chart below shows the risk profile: agent overreach at 92%, unsafe tool calls at 80%, and forbidden phrase output at 74%.
How the mechanism works: the permission bitmask step by step
This is the core of best practices for implementing LLM access controls and monitoring. The mechanism sits directly in the request path, between the user request and the model output.
User request with bitmask. The calling application authenticates the user and passes a raw integer bitmask, for example
7. reskSecure does not handle JWT or authentication. It receives the integer.BitmaskLogitsProcessor intercepts each token prediction. The processor is a
LogitsProcessorsubclass. It wraps the model generation loop. Every candidate token must pass through the security policy before being sampled.Aho-Corasick automaton checks banned phrases. For every candidate token, the
VectorizedAhoCorasickfrom theresklogitspackage checks if selecting that token would start or complete a banned phrase. This is GPU-accelerated pattern matching.Hard mode sets logit to
-inf. If the phrase is in hard mode, the token logit becomes impossible to generate. Bias mode reduces the logit by a configurable penalty, for example-5.0.On complete match, EOS is forced. Generation stops immediately. The model never sees the banned sequence as a completion candidate.
Tool calls are blocked at the token level. If the user bitmask does not contain the required bit for a tool, that tool trigger phrases like
send_email(orcreate_ticket(are automatically added to the hard-mode blocked list. The model can never generate the first token of a disallowed tool call.Post-generation check as defense in depth.
verify_tool_actionchecks the tool call against the bitmask before execution. The primary protection remains at the logits level.
Before — without it
No access control. The model can generate any tool call.
outputs = model.generate(**inputs)
response = tokenizer.decode(outputs[0])
Unsafe: no bitmask check, no phrase blocking
if has_tool_call(response):
execute_tool(response) # send_email, delete_table, anything
After — with reskSecure
from resksecure import BitmaskLogitsProcessor, load_policy, verify_tool_action
policy_set = load_policy("policy.yaml")
processor = BitmaskLogitsProcessor(
mask=7,
model_name="mistralai/Mistral-7B-v0.1",
tokenizer=tokenizer,
policy_set=policy_set,
device="cuda",
)
outputs = model.generate(**inputs, logits_processor=[processor])
Defense in depth: verify tool calls against the bitmask
if has_tool_call(response):
if not verify_tool_action("send_email", user_mask=7, policy_set=policy_set):
raise PermissionError("Action not authorized")
What changed
- Single source of truth. The bitmask is the only place capabilities are defined. No scattered if-statements.
-
Pre-sampling blocking. Forbidden phrases never become candidates. Hard mode sets logits to
-inf. - Tool calls blocked before execution. Trigger phrases are added to the hard-mode list when the required bit is missing.
- Strict mode available. Forces EOS as soon as the generated prefix matches the start of a banned phrase.
- Policy system. YAML configuration associates capability bitmasks with phrase rules and tool permissions.
-
Hot-reload.
PolicyWatcherdetects file changes and rebuilds the automaton without restarting the server. -
Thread-safe cache. Automata are cached by
(mask, model_name)with configurable TTL.
Best practices checklist
- Define one bit per capability. Keep the bitmask as the single source of truth for what an agent can do.
-
Use hard mode for destructive phrases.
DROP TABLE,DELETE FROM, and tool trigger phrases should be-inf. -
Use bias mode for sensitive but not forbidden terms. A penalty like
-5.0reduces probability without hard blocking. - Enable strict mode for high-risk agents. Stop generation at the first banned prefix, not just the full phrase.
-
Always verify tool actions post-generation.
verify_tool_actionis defense in depth, not the primary control.
Honest limitations
reskSecure does not handle authentication or JWT decoding. The calling application must pass a raw integer bitmask. The package requires Python >= 3.13, PyTorch >= 2.0.0, transformers >= 4.35.0, and resklogits >= 0.1.0. Commercial use requires a separate paid license under the RESK Software License. Logits-level filtering is strong, but it is not a substitute for a full security architecture. It is one layer.
Conclusion
Best practices for implementing LLM access controls and monitoring converge on one idea: enforce capabilities before generation, not after. A permission bitmask gives you a single source of truth. reskSecure implements it at the logits level, blocking forbidden phrases and unsafe tool calls before they exist.
- Website: resk.fr — AI Security Tools for Enterprise
- GitHub: github.com/Resk-Security
- PyPI: pypi.org/project/resksecure

Top comments (0)