Skip to main content

DBShield Python SDK

Safety-first database guardrail, SQL AST firewall & sandboxing wire proxy for autonomous AI coding agents in Python.

Protect your databases from accidental bulk deletes, catastrophic drops, locks, and PII leaks when paired with LangChain, CrewAI, LlamaIndex, SQLAlchemy, Cursor, and Claude Code.


📦 Installation

pip install dbshield-defense

(In Python code, import as standard import dbshield or from dbshield import DBShieldGuard)


⚡ Quickstart

1. Standalone Query Guardrail

Validate raw SQL queries before execution without any external server dependencies:

from dbshield import DBShieldGuard

guard = DBShieldGuard(safety_tier="BALANCED")

# 1. Blocks dangerous tautology mutations
result = guard.validate_query("DELETE FROM users WHERE 1=1;")
if not result.allowed:
    print(f"Blocked: {result.violations[0].message}")
    # Output: Blocked: Unconstrained mutation: WHERE clause contains tautology '1=1'

# 2. Blocks destructive DDL drops
result = guard.validate_query("DROP TABLE accounts;")
assert not result.allowed

# 3. Allows safe targeted queries
result = guard.validate_query("SELECT id, name FROM users WHERE id = 42;")
assert result.allowed

2. Automatic SQLAlchemy Middleware

Hook DBShield directly into your SQLAlchemy engine to protect against rogue agent mutations:

from sqlalchemy import create_engine
from dbshield.middleware import attach_dbshield

engine = create_engine("sqlite:///production.db")
attach_dbshield(engine, safety_tier="BALANCED")

# Any agent query executed through this engine is automatically validated!
with engine.connect() as conn:
    conn.execute("SELECT * FROM users WHERE id = 1;") # Safe
    conn.execute("DELETE FROM users;") # Raises DBShieldSecurityViolation!

3. Dynamic Zero-Leak PII Masking

Redact SSNs, credit cards, emails, and API keys from tabular results before feeding into LLM context:

from dbshield.pii import PiiRedactor

redactor = PiiRedactor()

rows = [
    {"id": 1, "email": "alice@example.com", "ssn": "123-45-6789", "token": "sk-proj-xyz"}
]

clean_rows = redactor.redact_rows(rows)
print(clean_rows)
# Output: [{'id': 1, 'email': 'a***e@e****e.com', 'ssn': '[REDACTED:SSN:39a1]', 'token': '[REDACTED:SECRET:9b1a]'}]

4. LangChain Integration

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

db = SQLDatabase.from_uri("sqlite:///app.db")
safe_db = DBShieldSQLDatabase(db, safety_tier="BALANCED")

# Executes safely with AST guardrails and PII masking
res = safe_db.run("SELECT * FROM users LIMIT 5;")

5. CrewAI Database Tool

from dbshield.integrations.crewai import DBShieldDatabaseTool

tool = DBShieldDatabaseTool(database_url="sqlite:///company.db")
# Pass 'tool' to your CrewAI agent

🏛️ Enterprise Compliance

  • 100% Air-Gapped and Local-First
  • Zero External Telemetry
  • India DPDP Act 2023 & EU GDPR Ready
  • Verifiable SOC 2 Type II Controls

Metadata

Release files for dbshield-defense 0.2.1

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.1
File Size Uploaded Provenance Actions
dbshield_defense-0.2.1.tar.gz 14.9 kB Without provenance Details for dbshield_defense-0.2.1.tar.gz

Built distribution (wheel)

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

Total release size: 30.5 kB

Release files / dbshield_defense-0.2.1.tar.gz

Download URL dbshield_defense-0.2.1.tar.gz
Size 14.9 kB
Tags Source
SHA-256 checksum
How to use checksums
50c06a4dae3974af0bb96bdacd16f255fe0ff38a19ddb6308dc46756645987fd
BLAKE2b-256 checksum
How to use checksums
7a12d520d155b10e112e686b8f36a4e1413cf2c59919209df50962d188014b72
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL dbshield_defense-0.2.1-py3-none-any.whl
Size 15.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
58600a4e128b3cee55c3197c1d2b9b8d64d3513d2d559cb0bd1de6242cb0dbbd
BLAKE2b-256 checksum
How to use checksums
45479867ea20a41f2f0963ac8e24a03cec4f6e4ceb86431bf945fb2dbc7539a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for dbshield-defense 0.2.1

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.1 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