Querying the Audit Trail
Quick Search
Go to Governance → Audit Trail and use quick filters:
- Time Range: Last hour, day, week, month, or custom
- User: Select specific user or all users
- Model: Filter by AI model (gpt-4, claude-3, etc.)
- Status: Show blocked, allowed, or warned requests
- Violation Type: PII, injection, toxicity, etc.
Example: Find all blocked PII attempts in the last 24 hours:
- Time Range: “Last 24 hours”
- Status: “Blocked”
- Violation Type: “PII detected”
- Click Search
Advanced Query Syntax
Use the advanced search box for complex queries:
user:john@company.com AND model:gpt-4 AND violation:pii_detected AND decision:blocked AND timestamp:[2025-03-01 TO 2025-03-15]Field Operators
| Operator | Example | Meaning |
|---|---|---|
: | user:john@company.com | Exact match |
~ | prompt~"SQL injection" | Contains (text search) |
> | tokens>5000 | Greater than |
< | latency_ms<100 | Less than |
[..TO..] | timestamp:[2025-01-01 TO 2025-03-15] | Date range |
AND | user:john AND violation:pii | Both must match |
OR | violation:pii OR violation:injection | Either can match |
NOT | NOT decision:blocked | Exclude |
Searchable Fields
User/Request Info
user: User ID or emailuser_id: Numeric user IDuser_email: Email addressdepartment: Department namemodel: AI model nametimestamp: Date/timetokens: Token count
Decision/Status
decision: allowed, blocked, warnedviolation: Type of violationstage: Firewall stage (pii-scanner, injection-detector, etc.)confidence: Detection confidence (0.0-1.0)
Performance
latency_ms: Request latencyscan_latency_ms: Governance latency onlytokens: Token count
Query Examples
Find All PII Violations by User
user:jane@company.com AND violation:pii_detectedReturns: Every time Jane’s request contained PII
Find High-Confidence Injections This Month
violation:injection_detectedAND confidence>[0.9]AND timestamp:[2025-03-01 TO 2025-03-31]Returns: High-confidence injection attempts from March
Find All Requests Over 10 Seconds
latency_ms>10000Returns: Slow requests for performance analysis
Find Requests by Department
department:marketing AND decision:blockedReturns: All blocked requests from marketing department
Find Policy Violations by Stage
stage:content-safety AND decision:blockedReturns: All content safety violations that were blocked
Find Warnings (Not Blocks)
decision:warned AND violation:toxicity_detectedReturns: Requests that triggered toxicity warnings but weren’t blocked
Saved Searches
Create search templates you use regularly:
- Go to Governance → Audit Trail → Saved Searches
- Click + New Saved Search
- Name: “PII Incidents”
- Query:
violation:pii_detected AND decision:blocked - Click Save
Now you can run this search anytime from the dropdown.
Common Saved Searches:
- “Security Incidents”:
decision:blocked AND violation:(pii_detected OR injection_detected) - “High Latency”:
scan_latency_ms>200 - “User Compliance”:
user:$USER AND timestamp:[LAST_7_DAYS] - “Policy Testing”:
policy:test-policy AND timestamp:[LAST_24_HOURS]
Aggregations & Analytics
Click Analytics to see trends:
By Violation Type
Pie chart: % of violations by typePII: 45%Toxicity: 25%Injection: 20%Other: 10%By Decision
Bar chart: Blocked vs. allowed by dayMar 13: 15 blocked, 2500 allowedMar 14: 8 blocked, 2400 allowedMar 15: 12 blocked, 2600 allowedBy User
Table: Top users with violationsuser123: 15 violationsuser456: 12 violationsuser789: 8 violationsBy Stage
Bar chart: Violations detected per stagePII Scanner: 125Content Safety: 78Injection Detector: 45Truth Scanner: 32Latency Distribution
Histogram: Request latency<50ms: 40%50-100ms: 35%100-200ms: 20%>200ms: 5%Exporting Results
Quick Export
- Run query
- Click Export
- Choose format:
- CSV: For spreadsheets
- JSON: For programmatic use
- PDF: For printing/sharing
- Download
Scheduled Exports
Export audit logs automatically on a schedule:
- Go to Governance → Audit Trail → Scheduled Exports
- Click + New Scheduled Export
- Query: Your search query
- Schedule: Daily, weekly, monthly
- Format: CSV, JSON, or PDF
- Recipients: Email addresses
- Click Create
Now you’ll receive audit reports automatically!
API Access
Query audit logs programmatically:
REST API
curl -X GET "http://localhost:5000/api/v1/governance/audit/logs" \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{ "query": "violation:pii_detected AND decision:blocked", "limit": 100, "offset": 0, "sort": "timestamp:desc" }'Response:
{ "total": 45, "returned": 20, "entries": [ { "id": "log_abc123", "timestamp": "2025-03-15T10:23:45Z", "user_id": "user_123", "model": "gpt-4", "decision": "blocked", "violation": "pii_detected", "confidence": 0.98 } ]}Python SDK
from truthvouch import TruthVouchClient
client = TruthVouchClient(api_key="tvk_...")
# Query audit logsresults = client.governance.audit.query( query="violation:pii_detected AND decision:blocked", start_date="2025-03-01", end_date="2025-03-31", limit=100)
for entry in results: print(f"{entry.timestamp} - {entry.user_id}: {entry.violation}")
# Get summary statisticsstats = client.governance.audit.stats( query="violation:*", group_by="violation")
print(stats)# Output:# {# "pii_detected": 45,# "injection_detected": 20,# "toxicity_detected": 15# }Performance Tips
For Large Datasets:
-
Use Date Ranges: Instead of querying all time, specify a date range
timestamp:[2025-03-01 TO 2025-03-15] # Not timestamp:[*] -
Limit Results: Don’t retrieve 1 million entries at once
Get first 100, then paginate if needed -
Index Common Filters: Queries on indexed fields are fast
user— indexedtimestamp— indexeddecision— indexedviolation— indexed
-
Avoid Text Search: Full-text search in request content is slow
# Slow:prompt~"specific text"# Fast:violation:pii_detected AND decision:blocked
Real-World Scenarios
Scenario 1: Investigate User Behavior
Goal: Review john@company.com’s recent activity
user:john@company.com AND timestamp:[LAST_7_DAYS]What you see:
- 847 total requests
- 3 blocked (PII detected)
- 5 warnings (content safety)
- Avg latency: 95ms
Action: Email john about PII blocking rules
Scenario 2: Audit Compliance
Goal: Prove to auditors that PII masking is working
violation:pii_detected AND decision:blockedAND timestamp:[2025-01-01 TO 2025-03-31]What you see:
- 247 PII detection events blocked
- 100% effectiveness (0 PII leaked)
- Distributed across 45 users
- Confidence avg: 0.94
Export as: PDF for auditor
Scenario 3: Detect Attack Patterns
Goal: Find potential prompt injection attempts
violation:injection_detected AND confidence>[0.7]AND timestamp:[LAST_24_HOURS]What you see:
- 8 high-confidence injection attempts
- From 3 different IP addresses
- All blocked successfully
- Patterns: “ignore system”, “forget instructions”
Action: Alert security team about suspicious IPs