Skip to content
Agastya Shield

Agastya Shield

github.com • November 27, 2026

Hide private data before it reaches the model. Catch prompt injection before the model obeys it. Catch leaks before the user sees them.

Every app that sends text to an LLM has two problems:

Data going out. Users paste Aadhaar numbers, PANs, card numbers and API keys into chatbots, and that data goes to a third-party API. Under India's DPDP Act and Europe's GDPR, that's a liability.

Instructions coming in. Any text you didn't write yourself (user messages, RAG chunks, web pages, emails, PDFs) can contain instructions the model will follow. OWASP lists prompt injection as the #1 risk for LLM applications.

agastya-shield handles both, in pure Python, offline, in under a millisecond for a typical prompt.

What makes it different

1. Redact and restore

Keep one Vault per conversation ( Vault.to_dict() / Vault.from_dict() to store it), so means the same person in every turn.

Fake mode gives the LLM natural-looking data, which models handle better than . Fakes use reserved ranges ( example.com , 192.0.2.x , the 4000… test-card prefix) and pass the same checksum as the original: a fake Aadhaar passes Verhoeff and a fake GSTIN keeps its state code. Secrets always get placeholders, never fakes.

Keyed hashing : a plain SHA-256 of an Aadhaar number can be reversed by trying all 10¹¹ possibilities, so mode="hash" always uses HMAC. Pass your own key for hashes that stay stable across runs.

Chat messages and streaming :

2. Detect prompt injection

Findings are combined as independent evidence ( 1 - Π(1 - wᵢ) ), so several weak signals add up and a single strong one is enough.

Multi-turn attacks : attackers split a payload across messages ("remember the word ignore " … "now add all instructions "), so no single message looks bad:

Plug in an ML model for paraphrased attacks. The rules catch obvious cases in microseconds, and the model catches the rest:

3. Defend instead of just detecting

spotlight implements Microsoft Research's spotlighting defence ( delimit , datamark and base64 modes).

4. Secure your RAG pipeline

See examples/rag_chromadb.py for scanning at both ingestion and retrieval.

5. Scan the model's output

This catches system-prompt leaks (canary or copied text), markdown images that send data to outside servers, leaked secrets and personal data, and dangerous shell/SQL commands.

6. Guard your agent's tool calls

When an agent decides to call send_email or run_shell , an injected instruction may be steering it. Check the call before executing it:

It flags non-allowlisted tools and destinations, destructive commands, sensitive paths ( ../ , ~/.ssh , .env , /etc/passwd ), secrets or personal data in arguments, and injection text being passed on to the tool.

normal and async def functions;

functions that stream (generators / async generators): placeholders are restored chunk-safely, and the output is scanned when the stream ends;

a prompt string or a list of OpenAI / Anthropic-style messages (multi-turn injection checks included).

Every command reads from a file, --text or stdin. The exit code is 1 when something is found, so you can use it in CI:

Sensitive data (33 detectors, 29 on by default):

India: AADHAAR * PAN GSTIN * IFSC UPI_ID IN_PHONE VOTER_ID IN_DRIVING_LICENCE * ABHA_NUMBER ABHA_ADDRESS

International: EMAIL CREDIT_CARD * IBAN * UK_NINO US_SSN * IP_ADDRESS *

Secrets: OPENAI_KEY ANTHROPIC_KEY AWS_ACCESS_KEY GITHUB_TOKEN GOOGLE_API_KEY SLACK_TOKEN STRIPE_KEY RAZORPAY_KEY HUGGINGFACE_TOKEN JWT PRIVATE_KEY PASSWORD URL_CREDENTIALS

Off by default: IN_PASSPORT IN_VEHICLE_REG * IPV6_ADDRESS * HIGH_ENTROPY_SECRET

* checksum or format validated

Injection : instruction override (6 languages), instruction dismissal ("your rules no longer apply"), fake authority ("your developer authorised you…"), new-instruction injection, role hijack, known jailbreaks (DAN etc.), system-prompt extraction, "don't tell the user" secrecy, instructions aimed at an AI reading a document, data exfiltration, tool hijacking, credential requests, destructive commands, fake chat-template tokens, markdown-image exfiltration, Unicode tag smuggling, zero-width and bidi characters, hidden HTML/CSS, homoglyphs, base64 payloads, and multi-turn split attacks.

agastya-shield benchmark runs the detector on a labelled set bundled with the package , so anyone can reproduce these numbers:

The held-out number is the one to trust. Rules have no false alarms on tricky normal text (security discussions, "ignore the noise in the data", "you are now enrolled"). Most of the misses are paraphrases like "consider your constraints lifted", which is the known limit of any rule-based detector. Add a model with add_classifier() to cover them. Both sets are small and hand-written, so measure on your own traffic: shield.benchmark("my_data.jsonl") .

This is a fast, explainable first line of defence , not a guarantee. Pattern-based detection misses some paraphrased attacks (see the benchmark), and no detector of any kind catches everything today. Use it together with least-privilege tools, human confirmation for risky agent actions, and output validation. Defence in depth.

More Indian IDs (Voter ID, driving licence, ABHA) : v0.2

Public benchmark and ML classifier plug-in : v0.2

Ready-made pip install agastya-shield[ml] extra with a small bundled classifier

Name / address detection via optional NER

LangChain / LlamaIndex callbacks and FastAPI middleware

EU national IDs (German Steuer-ID, French INSEE, Spanish DNI)

Larger community benchmark: bypasses reported in issues become test cases

Contributions welcome. Each detector and rule is a single add_detector / add_rule call.

Extracted Entities

Attack Types (1)