Skip to main content

DBShield Python SDK 🛡️

PyPI version Python 3.10+ License: MIT Interactive Playground Trust Center

Enterprise-grade Database Guardrail & Wire Proxy Python SDK for Autonomous AI Agents built with LangChain, CrewAI, LlamaIndex, and SQLAlchemy.

Documentation • Web Portal • Trust Center • Issues


⚡ Key Features

  • AST Query Validator: In-memory SQL AST query analyzer detecting tautologies (WHERE 1=1), destructive DDL (DROP TABLE, TRUNCATE), unindexed queries, and row read ceilings.
  • Dynamic PII Redactor: Format-preserving pseudonymization and regex redaction for SSNs, Luhn-valid credit card numbers, email addresses, and JWT/API tokens.
  • Two-Phase Commit Distributed Sandbox: Dry-run simulation with automatic rollback and single-use HMAC-SHA256 commit tokens.
  • Transparent Middleware: DB-API 2.0 cursor wrappers (DBShieldConnectionWrapper) and SQLAlchemy hooks (attach_dbshield) with zero application refactoring.
  • AI Agent Framework Integrations:
    • LangChain: DBShieldSQLDatabase and DBShieldQueryTool
    • CrewAI: DBShieldDatabaseTool
    • LlamaIndex: DBShieldLlamaIndexTransform
  • 100% Air-Gapped & Zero Telemetry: Operates strictly local-first within air-gapped private VPC networks.

📦 Installation

pip install dbshield-defense

Note: In code, import as standard import dbshield or from dbshield import DBShieldGuard.


🚀 Usage Guide

1. In-Memory AST SQL Guard

Validate queries generated by LLMs before execution:

from dbshield import DBShieldGuard

guard = DBShieldGuard()

# 1. Block destructive operations
result = guard.validate_query("DROP TABLE users")
print(result.allowed)     # False
print(result.risk_level)  # "CRITICAL"
print(result.violations)  # [Violation(code='DESTRUCTIVE_DDL_PROHIBITED', ...)]

# 2. Block unconstrained mutations and tautologies
result = guard.validate_query("DELETE FROM orders WHERE 1=1")
print(result.allowed)     # False

2. Dynamic PII Redaction & Format Preservation

from dbshield import PiiRedactor

redactor = PiiRedactor()

text = "User SSN is 000-12-3456 and email is john@acme.com"
sanitized = redactor.redact_text(text)
print(sanitized)
# -> "User SSN is [REDACTED:SSN:9705bb] and email is j***n@a****e.com"

3. Transparent SQLAlchemy Integration

from sqlalchemy import create_engine
from dbshield import attach_dbshield

engine = create_engine("postgresql://user:pass@localhost:5432/proddb")

# Attach DBShield interceptor hook
attach_dbshield(engine)

# All queries executed via engine are now validated and PII-sanitized automatically!

4. LangChain Integration

from dbshield.integrations.langchain import DBShieldSQLDatabase, DBShieldQueryTool
from langchain_community.utilities import SQLDatabase

raw_db = SQLDatabase.from_uri("sqlite:///analytics.db")
shield_db = DBShieldSQLDatabase(raw_db)

# Create an agent tool that refuses destructive DDL or tautology queries
tool = DBShieldQueryTool(db=shield_db)

5. CrewAI Database Tool

from dbshield.integrations.crewai import DBShieldDatabaseTool
import sqlite3

conn = sqlite3.connect("company.db")
db_tool = DBShieldDatabaseTool(connection=conn)

# When an autonomous CrewAI agent generates a query:
output = db_tool._run("SELECT name, email FROM customers WHERE active = 1")
print(output)  # Rows returned with sensitive PII automatically masked!

6. LlamaIndex Transform

from dbshield.integrations.llamaindex import DBShieldLlamaIndexTransform

transform = DBShieldLlamaIndexTransform()
safe_response = transform.postprocess_response("Query returned user SSN 000-12-3456")

🔒 Security & Compliance

  • Zero Cloud Exfiltration: Runs 100% locally with DBSHIELD_AIR_GAPPED=1.
  • Pre-filled SIG Lite / CAIQ: Download the Vendor Risk Assessment Packet at ritualdev.in/trust.
  • Statutory Alignment: Designed for India DPDP Act 2023, EU GDPR, and SOC 2 Type II.

📄 License

MIT © RitualDev Studio

Metadata

Release files for dbshield-defense 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dbshield-defense 0.2.0
File Size Uploaded Provenance Actions
dbshield_defense-0.2.0.tar.gz 18.5 kB Without provenance Details for dbshield_defense-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dbshield-defense 0.2.0
File Interpreter ABI Platform Actions
dbshield_defense-0.2.0-py3-none-any.whl Python 3 none any Details for dbshield_defense-0.2.0-py3-none-any.whl

Total release size: 36.0 kB

Release files / dbshield_defense-0.2.0.tar.gz

Download URL dbshield_defense-0.2.0.tar.gz
Size 18.5 kB
Tags Source
SHA-256 checksum
How to use checksums
fa5e099243a009fa3dedf85e5bee7cce2032e28e049d8c2be018df39ecf0b00b
BLAKE2b-256 checksum
How to use checksums
72509533753ecc273845b5baf70e4d49baf59e31489c22c953579dbba52e4b77
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.2

Release files / dbshield_defense-0.2.0-py3-none-any.whl

Download URL dbshield_defense-0.2.0-py3-none-any.whl
Size 17.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7ce3f784b76f6d2819da17273ac0902327f2d9e96e7daa813496f78001aee00f
BLAKE2b-256 checksum
How to use checksums
a4becc40360537fab462aa2616ea34b8b0cb3e9cead8b27464b3812a4160b02d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.2

Security for dbshield-defense 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page