← All Insights

PRIMESHIFT INSIGHTS · November 12, 2025

Prompt Injection Hardening for Enterprise Copilots Accessing Internal SQL Schemas

Why natural-language SQL generation needs read-only DB views, Postgres RLS isolation, and AST query validation rather than regex filters.

Modular deterministic AI policy guardrail pipeline and evaluation gate schematic
WED, NOV 12, 2025·7 min read·AI & Evals·Issue #12 · Core Dispatches
Dispatch Issue #12 · Key Metric: Blocked 100% of indirect prompt-injection & cross-table exfiltration vectors

Production Context & Why This Matters

Allowing internal enterprise copilots to synthesize ad-hoc SQL strings directly against production database credentials exposes sensitive tables whenever untrusted ticket or email text enters the prompt context.

Asking an LLM nicely inside system prompts not to run `DROP` or query `users_secrets` offers zero real security boundary. Robust hardening treats generated SQL strictly as untrusted user input.

Architectural Mechanics & Reference Implementation

Parsing every candidate query via a SQL AST analyzer against allowlisted read-only views—and running execution under a `READ ONLY` role guarded by PostgreSQL RLS—enforces defense in depth.

CREATE ROLE ai_copilot_reader NOINHERIT LOGIN;
SET ROLE ai_copilot_reader;
SET default_transaction_read_only = on;
SET statement_timeout = '3000ms';

Verified Operational Benchmarks

Red-team exercises attempting encoded union injections and schema enumeration failed cleanly against AST validation + read-only RLS roles.

  • Primary Delta: Blocked 100% of indirect prompt-injection & cross-table exfiltration vectors
  • Reliability Gate: Zero write/DDL statements or system-catalog queries permitted on copilot pools
  • Ownership Boundary: 100% client-owned IaC & telemetry pipelines audited by Randeep Kaur

Implementation Checklist

  • Expose only curated analytical views to text-to-SQL agents, never raw core tables.
  • Parse generated SQL structurally with an AST whitelist allowing SELECT statements only.
  • Enforce hard 3-second statement timeouts so runaway joins cannot exhaust IOPS.
About the Author

Randeep Kaur

Lead Technical Editor & Engineering Research Correspondent

Lead Technical Editor directing systems architecture dispatches, AI deterministic evaluation research, regulated cloud compliance analyses, and weekly engineering briefings at PrimeShift Digital.

Read All Stories by Randeep Kaur →

In This Dispatch

Evaluating this architecture inside your production stack?

Our Principal Engineering Desk runs two-week topology audits directly inside your organization cloud & GitHub repos.