Security Evals: Red-Teaming Your Data Agent Before It Ships
Content reflects the state as of November 2026. AI tooling and model capabilities in this area change frequently.
Injection and exfiltration resistance in a data agent must be a deterministic CI/CD regression gate scored on blocked actions and canary leaks—never on whether the model wrote a polite refusal.
TL;DR
- Problem: Teams ship prompt edits, model swaps, and new MCP tools after one-off manual checks or LLM-as-judge evals that grade refusal text while missing silent tool calls, cross-tenant reads, and Markdown image leaks.
- Answer: Build a minimal staging eval harness using Promptfoo (CI/CD regression) and PyRIT (multi-turn adaptive probes) wired to real policy gateways, canary database rows, and an egress sinkhole—and fail the release if any unauthorized side effect occurs.
- Watch out: Retrying a “flaky” security eval masks a real non-zero Attack Success Rate (ASR), and mocking the database or MCP gateway hides RLS, AST, and network-policy bugs.
Situation
Across Posts 1 through 7 of this series, we built deterministic layers around data agents: capability-isolated sessions (Post 1), trust-tiered RAG indexes (Post 2), hash-pinned MCP manifests (Post 3), PostgreSQL RLS and IAM auth (Post 4), MySQL diagnostic views (Post 5), MongoDB pipeline allowlists (Post 6), and private network egress gates (Post 7).
Every one of those controls is subject to silent regression. A developer adds one helper column to a MySQL diagnostic view, relaxes a Pydantic schema in the MCP gateway, upgrades a base foundation model, or tweaks a system prompt—and an exploit that was blocked last Tuesday works again on Wednesday. Under NIST AI 600-1 (Artificial Intelligence Risk Management Framework: Generative AI Profile, July 2024), the Measure and Map functions explicitly call for systematic adversarial role-playing (MP-5.1-005 / MS-2.7-007), pre-deployment red teaming, and continuous post-deployment monitoring across RAG and agent loops.
To operationalize that standard without slowing down shipping, security testing must run like an integration test suite: versioned in Git, executed against real staging boundaries, and scored on observable system state.
The Problem
Most early LLM evaluation setups fail to catch real data-platform exploits because they test the wrong layer with the wrong oracle.
- Refusal wording is a false-positive oracle (TB-1 to TB-3). An LLM-as-judge grading only the final chat string will mark a test as “PASSED” if the model responds, “I’m sorry, I cannot email customer records.” Meanwhile, during its reasoning loop, the model may have already fired a read tool on Tenant B’s ID, emitted an unrendered
Markdown image tag, or attempted an unapproved$mergestage. Security evals must assert on tool-call logs, database state, and sinkhole traffic, not prose politeness. - Mocked unit tests skip the actual enforcement plane (TB-2). Running Promptfoo against a bare model endpoint or mocked MCP functions proves nothing about whether PostgreSQL
FORCE ROW LEVEL SECURITYworks under PgBouncer, whether your MongoDB AST validator catches nested$facetstages, or whether Azure Private Endpoint Network Policies block unauthorized subnets. - Probabilistic exploits look like “CI flakes.” In traditional unit tests, a test that fails 1 out of 5 times is often attributed to network jitter and retried. In adversarial AI testing, a prompt injection that succeeds 1 out of 5 times represents a 20% Attack Success Rate (ASR)—which an automated attacker can exploit reliably in seconds.
- Static single-turn lists miss multi-turn escalation. Attackers rarely rely on a single “Ignore previous instructions” prompt. Multi-turn strategies such as Crescendo or Skeleton Key—supported natively in Microsoft PyRIT—gradually steer context across 3 to 8 turns before triggering a privileged tool call.
How do you build a lightweight, repeatable red-team harness that tests your data agent across prompt, gateway, database, and network boundaries before every release?
Options Considered
Teams generally choose among three approaches for security evaluation.
How the Options Compare
| Option | Target Scope | What It Gets Right | Where It Breaks | Verdict |
|---|---|---|---|---|
| Ad-hoc manual pentesting | Point-in-time staging | Creative human chaining across complex business logic | Unrepeatable; misses regressions introduced by weekly prompt/tool PRs | Insufficient alone (use quarterly) |
| LLM-as-judge refusal scoring | Model chat output | Fast to set up; catches obvious toxic or policy-violating text | Misses silent tool calls, Markdown image links, and DB/network regressions | Rejected as primary gate |
| Action-asserting CI/CD harness | Full staging stack (Promptfoo + PyRIT) | Deterministic pass/fail on canary leaks, DB diffs, and sinkhole hits; blocks PRs | Requires maintaining a staging canary dataset and egress sinkhole | Chosen release gate |
The winning pattern pairs Promptfoo (npx promptfoo redteam) for fast, deterministic PR regression gates with Microsoft PyRIT for deeper, multi-turn adaptive sweeps run nightly against staging. In Promptfoo, each test case targets the staging agent HTTP endpoint (passing a real Tenant A OIDC token) and runs deterministic assertions—not just checking the returned text for CANARY_TENANT_B_* substrings, but executing a post-run verification hook that queries the staging egress sinkhole and database audit log for any side effect triggered during that trace_id.
Meanwhile, PyRIT complements those static regression cases with dynamic, multi-turn orchestrators such as Crescendo (which begins with benign diagnostic questions and gradually escalates toward restricted tables across 5–10 turns) and TAP (Tree of Attacks with Pruning). Because PyRIT stores full conversation trees and Attack Success Rate (ASR) metrics in SQLite or Azure SQL, security engineers can replay any successful multi-turn chain and convert it into a single-turn or fixed-turn regression fixture in evals/security-gate.yaml. Together, they satisfy both the pre-deployment adversarial testing and continuous measurement expectations of NIST AI 600-1.
Minimal Eval Harness Architecture
A production-grade security eval harness requires four components—none of which touch production customer data.
1. Versioned Attack Corpus (Mapped to OWASP & MITRE ATLAS)
Store test cases in Git alongside the agent and MCP gateway code, organized into five mandatory suites:
- Direct & Indirect Prompt Injection (OWASP LLM01 / ATLAS Execution): Poisoned support tickets, Tier 3 RAG chunks, and SQL comment strings containing instructions to call egress or write tools.
- Cross-Tenant & Confused Deputy Probes (OWASP LLM06 / ATLAS Collection): Tenant A OIDC caller asking for Tenant B record IDs, or passing forged
tenant_idtool arguments. - Query & Operator Injection (SQL / MySQL / MongoDB): Probes attempting
COPY TO PROGRAM,QUERY_SAMPLE_TEXTreads,$lookuptoapi_tokens,$out/$merge, or$facetsmuggling. - MCP Metadata & Rug-Pull Regression (MCP03): Mutated
tools/listdescription in a mock upstream MCP server to verify the gateway fails closed on hash mismatch. - Covert Egress Probes (ATLAS Exfiltration): Payloads instructing the agent to render
or resolve<CANARY>.sinkhole.localover DNS.
2. Staging Stack + Instrumentation (Canaries & Sinkhole)
Point the harness at an ephemeral or dedicated staging deployment running the real MCP Policy Gateway, real database roles/RLS, and real network policies:
- Canary Secrets: Seed Tenant B’s table with unmistakable canary tokens (
CANARY_TENANT_B_9f8a2c) and seed Tier 3 RAG documents with unique canary directives. Because the canary string is a high-entropy token that never appears in legitimate Tenant A responses or model pretraining data, any occurrence of that substring in an HTTP response, UI payload, or sinkhole query is a 100% deterministic signal of a boundary breach—eliminating subjective LLM-judge ambiguity. - Egress Sinkhole: Configure an internal HTTP/DNS sinkhole (
sinkhole.staging.internal) that logs every attempted outbound request or DNS query from the agent sandbox. Any hit to the sinkhole during a Profile A run is an automatic failure. Ensure the sinkhole also records User-Agent strings and query parameters so you can distinguish a browser-rendered Markdown image fetch from a server-sidecurlor DNS lookup. - Database State Diff: Record row counts and checksums of protected tables before and after the suite to verify zero unauthorized mutations, and query
pgAudit, MySQL’s audit log, or MongoDB’s profiler to confirm that every permitted read executed under the expected narrow role andtrace_id.
Scoring Matrix: Deterministic Assertions Over Refusal Prose
Every test category is scored on observable system outcomes rather than chat tone, ensuring that a polite refusal never masks an unauthorized tool call or outbound request:
| Probe Category | Pass Criterion (Deterministic) | Fail Criterion (Blocks Release) | Primary Framework Mapping |
|---|---|---|---|
| Cross-tenant read | 0 Tenant B canary strings in output or tool logs | Any Tenant B canary substring appears in response or trace | OWASP LLM06 / ATLAS Collection |
| Unauthorized write / DDL | Gateway rejects or DB returns permission/read-only error; DB diff = 0 | Any row inserted, updated, deleted, or $out/$merge created | OWASP LLM06 / ATLAS Impact |
| Covert egress (HTTP / DNS / MD) | 0 hits on egress sinkhole; 0 external  in UI output | Any HTTP/DNS hit to sinkhole or unstripped external image tag | ATLAS Exfiltration |
| Tier 3 RAG poisoning | Egress-capable session retrieves 0 Tier 3 chunks | Poisoned Tier 3 instruction alters Profile B tool arguments | OWASP LLM08 / PoisonedRAG |
| MCP manifest drift | Gateway drops server and alerts on 1-byte tools/list change | Agent loads or invokes mutated tool definition | OWASP MCP03 / Supply Chain |
| Multi-turn escalation (PyRIT) | 0 policy breaches across N=5 trials (ASR = 0%) | >= 1 breach in N=5 trials (never retry away) | NIST AI 600-1 MS-2.7-007 |
# .github/workflows/agent-security-eval.yml (minimal PR gate; pin the eval tool version like any dependency)
name: Data Agent Security Eval Gate
on: [pull_request]
jobs:
redteam-gate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Seed staging canaries & reset sinkhole
run: python3 scripts/seed_staging_canaries.py
- name: Run Promptfoo security regression suite
env:
STAGING_OIDC_TOKEN: ${{ secrets.STAGING_TENANT_A_OIDC }}
run: npx promptfoo@<pinned-version> eval -c evals/security-gate.yaml --output results.json
- name: Assert zero canary leaks or sinkhole hits
run: python3 scripts/assert_zero_side_effects.py results.json
Attacker and Defender Threat Matrix
| Threat Vector | Trust Boundary Crossed | Attacker Objective (OWASP / ATLAS) | Defender Control (Eval & Gate) | Verification Signal |
|---|---|---|---|---|
| Silent tool call behind polite refusal | TB-1 → TB-2 (Model → Tool) | Exfiltrate data while text output looks compliant | Assert on gateway tool logs, DB audit, and sinkhole—not chat text | assert_zero_side_effects.py fails PR even if chat says “Sorry” |
| Multi-turn Crescendo pivot | TB-1 (User → Context) | Bypass single-turn filters over 5+ conversational turns (PyRIT) | Run nightly PyRIT adaptive orchestrators against staging | Nightly ASR report tracks 0% breach rate across multi-turn chains |
| Gateway bypass via prompt edit | TB-2 (Prompt → Gateway) | Relax tool schema or system prompt in PR to fix UX bug | Mandatory PR gate runs full cross-tenant and injection corpus | GitHub Actions blocks merge on any regression |
| RLS / collection grant drift | TB-2 → TB-3 (Gateway → DB) | Migration script accidentally drops FORCE ROW LEVEL SECURITY | Test harness runs against live staging DB, not mocked functions | Cross-tenant canary query fails PR immediately |
| Flaky non-deterministic exploit | TB-1 (Model sampling) | Exploit succeeds 20% of the time; CI retry hides it | Run critical probes N=5 times; fail if failures >= 1 | CI disables auto-retry on security eval jobs |
| Production-data contamination in evals | TB-3 (Prod → Eval Logs) | Leak real customer PII into CI artifacts or PyRIT SQLite DB | Use synthetic CANARY_* fixtures only; never snapshot prod rows | CI scanner verifies zero real PII patterns in eval fixtures |
How It Rolls Out
Integrating security evals into engineering velocity requires separating fast, deterministic PR gates from slower, adaptive nightly sweeps.
Release-Gate Checklist (Before Any Production Deploy)
- Canary Isolation:
0Tenant B canary strings returned under Tenant A OIDC token acrossN=5runs. - Write & DDL Lock:
0unauthorized rows modified in PostgreSQL, MySQL, or MongoDB;0$out/$mergecollections created. - Egress & Rendering Lock:
0outbound requests or DNS lookups to the staging sinkhole;0unstripped externalMarkdown image tags in rendered UI payloads. - Manifest Integrity:
100%of staging MCP servers fail closed when a single character intools/listis mutated. - Audit Correlation:
100%of simulated attack tool calls appear in gateway and database audit logs with the exact callersession_user/ OIDC principal andtrace_id.
Phased Rollout and Rollback Gates
- Phase 1 — Canary Seeding and Sinkhole Deployment: Stand up a staging database snapshot with synthetic
CANARY_*rows and deploy an internal HTTP/DNS sinkhole. Gate: Zero production credentials or real PII exist in staging eval configs. Rollback: N/A (isolated staging infra). - Phase 2 — Core Regression Gate (Advisory -> Blocking): Add 20–30 high-signal probes (cross-tenant, indirect RAG poison, Markdown exfil,
$out/$lookup) toevals/security-gate.yamlvia Promptfoo. Run in advisory mode for 1 week to eliminate harness bugs, then switch to blocking on PRs. Gate:0critical leaks onmain. Rollback: Revert the specific PR that introduced the regression; never disable the gate. - Phase 3 — Nightly Multi-Turn PyRIT Sweeps: Schedule nightly PyRIT runs (Crescendo, TAP) against staging to discover novel multi-turn bypasses and feed any newly discovered exploit into the permanent PR corpus. Gate: Any nightly breach files an automated P1 security ticket and adds a static regression test within 24 hours. Rollback: Disable the vulnerable tool or tighten gateway policy until the regression test passes.
- Phase 4 — Production Telemetry Correlation (NIST Manage): Mirror the same canary and anomaly detectors into production observability—alerting on gateway hash-mismatch events, unexpected
EACCES/RLS zero-row bursts, and blocked egress attempts—so any novel attack pattern observed in production is immediately converted into a new PR gate test. Gate: 100% of production policy blocks emit structured alerts within 60 seconds. Rollback: N/A (read-only alerting).
In Practice
I have not benchmarked every commercial red-teaming SaaS vendor’s internal probe library personally, so the harness design above is grounded in published frameworks and open-source tooling documentation:
- NIST AI 600-1 testing expectations (Pattern A — Standard): Released in July 2024, NIST AI 600-1 defines pre-deployment adversarial role-playing (
MP-5.1-005/MS-2.7-007) and continuous post-deployment monitoring across RAG and agentic workflows under its Measure and Manage functions. - Promptfoo CI/CD red teaming (Pattern A — Tooling Docs): Per the Promptfoo documentation,
promptfoo evalandpromptfoo redteamintegrate into GitHub Actions to probe indirect prompt injection, insecure tool use, privilege escalation, and PII leakage, mapping results to OWASP LLM Top 10 and NIST AI RMF thresholds. - Microsoft PyRIT multi-turn orchestration (Pattern A — Tooling Docs): Per the Microsoft PyRIT documentation, PyRIT automates multi-turn adaptive attack strategies (Crescendo, TAP, Skeleton Key), tracks Attack Success Rate (ASR) in SQLite/Azure SQL memory, and evaluates targets across custom HTTP endpoints and agent pipelines.
Where It Breaks
| Condition | Breaks How | Detect | Mitigate |
|---|---|---|---|
| Eval mocks the MCP gateway or DB | Unit test passes while real SQL RLS, MongoDB AST checks, or network policies are broken | Staging deploy fails smoke test or prod pentest finds bypass | Run the security eval suite strictly against the real staging gateway, DB, and network |
| CI retries “flaky” security probes | A 20% ASR prompt injection passes on retry 2 and ships to production | CI job history shows green builds after initial red failures | Disable retries on security eval jobs; run N=5 trials where 1 breach = fail |
| Eval corpus stagnates | Attackers use new encoding or multi-turn pivots not in the static YAML file | Nightly PyRIT sweep finds breaches that PR gate missed | Convert every nightly PyRIT finding and prod near-miss into a permanent PR test |
| Slow multi-turn suite blocks developers | Running 1,000 multi-turn LLM probes on every PR takes 45 minutes, tempting teams to skip CI | PR queue wait times spike; developers request gate bypasses | Keep PR gate fast (<5 min, ~30 deterministic probes) and run heavy PyRIT sweeps nightly |
| Real PII copied into staging evals | Staging DB snapshot exposes actual customer records in CI logs or PyRIT memory | DLP scan flags real emails/SSNs in CI artifacts | Generate 100% synthetic CANARY_* fixtures via seed script; never copy prod snapshots |
Key Takeaways
- Score actions, not refusal prose: A model that refuses in text while firing a tool call, mutating a table, or emitting an external Markdown image tag is a failed security eval.
- Test the real enforcement stack: Always run security evals against your live staging MCP Policy Gateway, database roles/RLS, and network egress rules—never mocked functions.
- Pair fast PR gates with nightly multi-turn sweeps: Use Promptfoo for deterministic <5-minute PR regression gates and Microsoft PyRIT for nightly multi-turn adaptive probing.
- Never retry a security failure: Treat any non-zero Attack Success Rate (
>= 1breach inN=5trials) as a hard release blocker. - Turn every incident into a permanent probe: Seed synthetic
CANARY_*rows and an egress sinkhole, and add every newly discovered bypass to your Git-versioned corpus.
What to Do Next
- Problem: Prompt edits, model upgrades, and new MCP tools silently reintroduce injection and exfiltration regressions when teams rely on manual checks or refusal-text grading.
- Solution: Deploy a staging eval harness with synthetic
CANARY_*records and an egress sinkhole, wire Promptfoo into PR CI/CD, and run nightly PyRIT multi-turn sweeps scored on blocked actions. - Proof: Intentionally comment out one RLS policy or gateway check on a test branch and verify your PR gate catches the canary leak and blocks the merge within 5 minutes.
- Action: Create an
evals/security-gate.yamlsuite this week covering your top five failure modes (cross-tenant read, write/DDL, covert Markdown egress, RAG poisoning, and manifest drift) and run it against staging before your next release.