Schedule icon
WorkingDirectory icon
Script icon
Process icon
If icon
Loop icon
StructuredOutputCompletion icon
Parallel icon
Create icon
SlackIncomingWebhook icon

Scan AI Agent Sessions for Leaked Secrets and PII

Daily leakage scanner for AI agent session transcripts, with layered secret and PII detectors, Luhn and mod-97 validation, entropy analysis, masked quarantine copies, a leakage scorecard with trend, Gemini triage, GitHub issues, and Slack alerts. Raw values are never recorded, only redacted forms and fingerprints.

Categories
AI

What it does

AI agents paste things. Users hand them API keys and payment cards, tools echo configuration and credentials into transcripts, and everything lands in session logs that nobody audits. This blueprint scans those transcripts every day with layered detectors: pattern matching for provider key shapes, tokens, and credential assignments, a Shannon entropy pass for unknown token shapes, and PII detectors that validate payment cards with the Luhn checksum and IBANs with mod-97 so lookalike numbers do not raise false alarms. Sessions with high or critical findings are quarantined as masked copies that reviewers can inspect safely, and the run produces a leakage scorecard (per-detector and per-category counts, leakage rate, trend against the previous run). Genuine new leakage is judged by Gemini and escalated to a GitHub issue and a Slack alert.

Safety property

A leakage scanner that logs the leaks would be worse than no scanner. Detected values are therefore never printed, logged, written to artifacts, or posted to GitHub or Slack. Every finding carries only the detector name, a redacted form (first and last characters), and a SHA-256 fingerprint of the value, which is enough to correlate the same secret across sessions and secret stores without exposing it. Quarantined session copies have the values replaced by redaction markers, and the LLM judge sees redacted evidence only.

Prerequisites

A JSON export of agent session transcripts (the bundled demo sessions show the shape). Three namespace secrets: GEMINI_API_KEY for the judging stage, GITHUB_TOKEN with issue-write scope on the tracking repository, and SLACK_WEBHOOK_URL for the alert channel. No secret values from the transcripts are needed as inputs; the scanner works on the transcripts alone.

How it works

  1. daily_leakage_scan (io.kestra.plugin.core.trigger.Schedule) runs the scanner daily at 05:00 UTC. Run it on demand after an incident or a logging change.
  2. ingest_sessions (Python scripts) loads session transcripts from a JSONL export URL, an override input, or the bundled synthetic demo set (planted leaks plus clean controls).
  3. scan_sessions (Python) applies the layered detectors: secret shapes and credential assignments, entropy analysis, and validated PII (Luhn for cards, mod-97 for IBANs). Each matched span is claimed once, so nothing is double-counted.
  4. quarantine_sessions (Python) holds sessions with high or critical findings and writes the quarantine manifest with per-detector reasons.
  5. build_scorecard (Python) produces the scorecard artifact (scorecard.json and scorecard.md) with per-detector, per-category, and per-severity counts, the leakage rate, the trend against the previous run, and the gate verdict.
  6. triage (Kestra flow tasks) branches on the gate: passing runs are recorded; failing runs go to judgement and escalation.
  7. judge_flagged_detectors (Gemini) decides for each flagged detector whether the findings are a genuine leak or test and fixture data, from redacted evidence only.
  8. escalate opens a GitHub issue and posts a Slack alert in parallel, while write_trend_record appends the run to the trend series.

How to adapt it

Tune entropy_threshold to your traffic (lower catches more unknown token shapes, at the cost of more judging), set max_total_findings to the volume your reviewers can clear in a day, and add detector patterns in scan_sessions for internal token formats. Point previous_scorecard_url at each published scorecard so the leakage trend builds over time.

See How

New to Kestra?

Use blueprints to kickstart your first workflows.