A real-time guard that reads every action an AI agent is about to take — each karma — and decides, in a single forward pass, whether it is dharmic (safe, aligned, within mandate) or adharmic (harmful, deceptive, theft, overreach). If adharmic, the action is stopped before it runs.
Dharma-Guard is a fine-tune of Laya (a non-autoregressive typed-decision model on a jhu-clsp/mmBERT-base encoder, 322M params). It is not a chatbot and not a content filter — it is a decision layer that sits between an agent and its tools and answers one question per tool call: should this be allowed, escalated to a human, or blocked?
verdict ∈ {allow, escalate, block} + 8 supporting judgements (see below)Modern agent-safety tools mostly pattern-match known attacks — injection strings, jailbreak phrases, blocklisted tools. Attackers move faster than blocklists. The bet behind Dharma-Guard is different: teach the guard a small set of timeless, universal principles about right action, and let it judge the action itself — including attacks no one has catalogued yet.
These principles are drawn from the sādhāraṇa dharma (universal duties) found across the Indian traditions — the Gita, Ramayana, the Dharmaśāstra, Buddhism and Jainism — deliberately keeping only the universal ethics and excluding anything caste-, birth- or gender-based. Mapped onto an AI agent acting in the world:
| Principle (yama / idea) | Classical meaning | What the guard checks |
|---|---|---|
| Ahiṃsā | non-harm | Does this action harm a person, their safety, money, or data? |
| Satya | truthfulness | Is the agent deceiving — including a technically true statement meant to mislead (the Aśvatthāmā half-truth)? |
| Asteya | non-stealing | Is this taking data, access, or funds that aren't the agent's to take? (betrayed trust — nikṣepa) |
| Aparigraha | non-grasping | Is the agent seizing privilege, scope, or power beyond what it was given? |
| Adhikāra | standing / authority | Does the agent actually have the authority to do this? (Draupadi's question — you cannot give away what isn't yours) |
| Svadharma | one's own duty | Is this within the agent's assigned mandate, or has it drifted? |
| Tamasic action | reckless action in darkness | Is this careless, irreversible, done without heed of consequence? (DROP TABLE on prod, deploy skipping canary) |
| Āpad-dharma / escalate | when in doubt, ask the wise | Uncertain or high-stakes-but-legitimate → escalate to a human, don't guess |
So karma = a tool call, svadharma = the agent's mandate, the Lakṣmaṇa-rekhā = the sandbox boundary, and the yamas = the hard rules. A guard grounded this way can refuse a novel harmful action because it violates a principle, not because it matched a signature.
Honest scope: this is a value framing that makes the safety taxonomy coherent and teachable — not a claim that the model "has" values. It is a classifier trained on labelled examples of these principles.
For each {state, questions} the model returns a verdict plus supporting labels (typed questions, answered in one pass):
verdict: allow / escalate / block (the decision)serves_request, untrusted_instruction (is it obeying injected content?), irreversibleharm_to_others, deception, data_theft, power_grab (the four violation classes)harm_severity: none / minor / serious / severestate is {agent_role, mandate, action, ...context} — the agent's role, what it was asked to do, and the concrete action it's about to take.
Measured the way the agent-safety literature reports: detection metrics (Precision / Recall / F1) plus Attack Success Rate (attacks that slip through — lower is better) and Utility (benign actions preserved, not over-blocked — higher is better). Positive = "flag" (block or escalate).
All test rows were held out from training. Positive = the guard flags the action (block or escalate).
AgentDojo held-out split — 183 agent actions from the banking / slack / travel / workspace suites (103 benign, 80 unsafe). In these attacks the injected text is not visible: the harm is only in the action itself (e.g. a payment quietly redirected to a different account).
| Guard (same 183 rows) | Attacks caught (Recall) ↑ | Attack Success Rate ↓ | Benign allowed (Utility) ↑ | F1 ↑ |
|---|---|---|---|---|
| Dharma-Guard (this model) | 98.8% | 1.3% (1 / 80) | 24.3% | 0.667 |
| ProtectAI DeBERTa-v3 prompt-injection v2 | 50.0% | 50.0% (40 / 80) | 61.2% | 0.500 |
| Reference: "block everything" | 100% | 0% | 0% | 0.608 |
Dharma holdout — 40 hand-written cases for the principles above (Aśvatthāmā half-truths, adhikāra overreach, tamasic recklessness, dharmic benign controls). None of these rows were trained on, but they come from the same authoring templates as the training seed.
| Guard (same 40 rows) | Recall ↑ | ASR ↓ | Utility ↑ | Exact 3-way verdict |
|---|---|---|---|---|
| Dharma-Guard | 100% | 0% | 100% | 40 / 40 (incl. 8 / 8 escalate) |
| ProtectAI DeBERTa-v3 prompt-injection v2 | 5.7% | 94.3% | 80.0% | — (binary) |
In-distribution — karanxa/agent-action-safety-dataset validation (4,000 rows): Precision 0.950 · Recall 0.983 · F1 0.966 · Utility 0.935 · 3-way accuracy 0.962.
escalate on AgentDojo; all 24 escalate cases became block. Lowering the block threshold does not help: the verdict probabilities sit at almost exactly 0 or 1. We tuned a threshold on half the split and tested on the other half, and benign actions allowed only went from 25.0% to 26.9%.{tool, args} calls. On AgentDojo it blocks even read-only lookups such as get_car_price_per_day. Training on benign structured tool calls is the planned fix; it has not been tested yet.Raw logs: eval/train_eval.log, eval/calibration_baseline.json. Latency: 56 ms per single call on a T4 (≈85 ms/row batched on long inputs).
From LlamaFirewall (Meta, 2505.03574):
| Guard | ASR ↓ | Utility ↑ |
|---|---|---|
| No guardrail | 17.6% | 47.7% |
| PromptGuard-2 (86M) | 7.5% | 47.0% |
| AlignmentCheck (Llama-4 Maverick) | 2.9% | 43.1% |
| LlamaFirewall (combined) | 1.8% | 42.7% |
These are not a head-to-head. LlamaFirewall's numbers come from a live-agent-loop harness on one attack pattern (important_instructions), where "Utility" means end-to-end task completion; ours is a labelled action-detection set where "Utility" means fraction of benign actions correctly allowed. Different harness, different denominator. The truly comparable point is the head-to-head above: an open prompt-injection classifier run on our exact rows. And no guard is a silver bullet: an independent 2026 study drove LlamaFirewall to 80% ASR under stronger attacks.
pip install git+https://github.com/NandhaKishorM/laya huggingface_hub
import json
import laya
from huggingface_hub import snapshot_download
path = snapshot_download("AshishDwi99/dharma-guard")
guard = laya.load(path, device="cuda") # or "cpu"
questions = json.load(open(f"{path}/questions.json"))
state = {
"agent_role": "customer-support assistant",
"mandate": "Answer the customer's billing question.",
"action": "Email the customer's full credit-card number to an external gmail address.",
}
out = guard.predict(state, questions)
print(out["answers"]["verdict"]["choice"]) # -> "block"
Use the full questions.json from this repo (the exact questions the model was trained on). Wire the guard in front of your tool executor: run it on the proposed tool call; allow → execute, escalate → route to a human, block → refuse.
karanxa/agent-action-safety-dataset (Apache-2.0) — agent tool-call safety labelsHeld out and never trained on: a clean stratified dharma holdout and a disjoint AgentDojo test split.
escalate does not transfer out of distribution yet. It works on the dharma holdout (8/8) but collapses to block on AgentDojo.Built on Laya by Nandha Kishor (Convai Innovations). Base encoder: jhu-clsp/mmBERT-base. Safety labels: karanxa/agent-action-safety-dataset. OOD cases inspired by AgentDojo.
@misc{dharma-guard,
title = {Dharma-Guard: a dharma-grounded real-time action guard for AI agents},
author = {Ashish Dwivedi},
year = {2026},
url = {https://huggingface.co/AshishDwi99/dharma-guard}
}
May all agents act with dharma. 🪔
jhu-clsp/mmBERT-base