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.
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.
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.
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 : AADHAAR * PAN GSTIN * IFSC UPI_ID IN_PHONE EMAIL CREDIT_CARD * IBAN * IP_ADDRESS * 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 , HIGH_ENTROPY_SECRET . * checksum or format validated
Injection : instruction override (6 languages), new-instruction injection, role hijack, known jailbreaks (DAN etc.), system-prompt extraction, "don't tell the user" secrecy, text addressed to the AI, data exfiltration, tool hijacking, credential requests, fake chat-template tokens, markdown-image exfiltration, Unicode tag smuggling, zero-width and bidi characters, hidden HTML/CSS, homoglyphs, base64 payloads.
This is a fast, explainable first line of defence , not a guarantee. Pattern-based detection can't catch every novel attack, and no detector of any kind can today. Use it together with least-privilege tools, human confirmation for risky agent actions, and output validation. Defence in depth.
Optional small ML classifier for injection ( pip install agastya-shield[ml] )
More Indian IDs (Voter ID, driving licence, ABHA health ID) and EU national IDs
Name detection via optional NER
LangChain / LlamaIndex / FastAPI middleware integrations
A public benchmark of attack and benign prompts
Contributions welcome. Each detector and rule is a single add_detector / add_rule call.
The full story
This article is one source in a clustered incident — the cluster page carries the summary, timeline and every other outlet covering it.
