Availability
Available from Tyk AI Studio v2.1.0.
Compliance Events are structured audit records that filter scripts can emit to flag governance-relevant activity, such as PII redactions, content rewrites, policy violations, or silent failures, without affecting whether the request is blocked or allowed. They flow through the same analytics pipeline as proxy logs and chat records, are stored centrally on the control plane, and surface in the Compliance dashboard for review, drill-down, and CSV export.
This page is the end-to-end reference. For filter script syntax, see Filters.
Why Compliance Events
Before v2.1, the only thing the compliance dashboard could count was 4xx proxy logs, that is, requests the gateway blocked. That misses the most common governance activity in practice: a filter quietly redacts an email address, rewrites a passage of text, or flags something suspicious while still allowing the request through. Those interventions are exactly what compliance teams need visibility into, and they previously left no trace beyond a debug log line. Compliance events fix that. Any filter script can attach a list of structured events to its output. The platform persists them, propagates them from edge gateways back to the control plane, exposes them via API and dashboard, and counts them in Prometheus, all without changing the filter’s block/allow decision.Event Schema
A compliance event has the following shape (ComplianceEventOutput in the script API):
Validation:
- Events without an
event_typeare silently skipped. This avoids polluting the table with empty records when a script branch builds the event partially. severityvalues outsideinfo|warning|criticalare coerced toinfo.event_typeon the API query side is limited to 100 characters; any longer is a 400.severityon the API query side is validated against the same whitelist; an invalid value is a 400.- All API queries use GORM parameterized queries, so SQL injection attempts in
event_typeorseverityare treated as literal string matches and return empty results.
Server-Side Enrichment
Scripts only declare the four fields above. The platform enriches each event at recording time with context from the filter execution site:Filter Scopes
filter_scope identifies which of the six filter execution sites recorded the event:
You can filter on
filter_scope indirectly via the dashboard drill-down, or by joining compliance_events.filter_name against your filter catalog.
Emitting Events from a Filter Script
In a Tengo filter script, setcompliance_events on the output object:
Behavior
- Recording is asynchronous. Events are queued and written by the analytics pipeline, so filter latency is unaffected.
- Compliance events never affect the block/allow decision. Setting
block: falsewith critical events is legitimate (the filter chose to redact rather than block); settingblock: truewith no events is also legitimate. - The list can be empty or omitted. Most filters won’t emit events on every invocation; typically only when a condition fires.
- Events are recorded per filter, per invocation. A single request can produce multiple events from multiple filters.
Edge Gateways
In a hub-spoke deployment, filter scripts run on the Edge Gateway, but compliance events live on the control plane. The propagation path is:- Filter script on the edge sets
compliance_eventsin its output. - The Edge Gateway’s analytics handler (
MicrogatewaAnalyticsHandler.RecordComplianceEvents) queues the events to the pulse plugin’s local buffer, which survives a gateway restart. - On the next analytics pulse (every 30 seconds by default), events are batched into the gRPC
AnalyticsPulsemessage asComplianceEventProtoentries. - The control server’s
SendAnalyticsPulsehandler reconstructs the compliance event from each entry, preservingLLMID,AppID,UserID, severity, type, description, metadata, vendor, and model name, and persists it.
aistudio_compliance_events_total counter on the control-plane /metrics endpoint and group by source.
Querying Compliance Events
Admin API
Example:
metadata is returned as a JSON-encoded string (the storage shape). Parse it client-side.
SQL
The underlying table iscompliance_events. Useful indexes:
(app_id, timestamp): composite, for per-app time-bounded queries.user_id,llm_id,filter_name,event_type,severity: single-column, for filtering.timestamp: for retention sweeps.
Dashboard Surfaces
The Compliance dashboard (/admin/compliance) was extended in v2.1 to surface compliance events alongside the existing blocked-request data.
Summary Cards
Two new cards next to the blocked-request total:- Critical Events: count over the selected window, with trend arrow. Escalates the card style above
COMPLIANCE_EVENTS_CRITICAL_ESCALATE_AT(default 1, since a single critical event already warrants attention). - Warning Events: count over the selected window, with trend arrow. Escalates above
COMPLIANCE_EVENTS_WARNING_ESCALATE_AT(default 20, since warnings are advisory and need to accumulate before they matter).
Policy Violations Tab
The summary is split into three counters:- Blocked: 4xx proxy logs (existing).
- Flagged: warning and critical compliance events that passed through (new).
- Affected Apps: distinct apps appearing in either source.
Filter Events Tab
A dedicated tab for compliance events with:- Severity totals (info / warning / critical) with a stacked timeline chart.
- Severity and event-type filters (the event-type dropdown is populated from observed values in the window).
- Pagination over the event list.
- Expandable rows showing the raw
metadataJSON. - CSV export wired to
GET /compliance/events.
App Risk Modal
Per-app risk score now includes event counts, withwarningEventWeight = 1 and criticalEventWeight = 3, so a single critical event contributes the same to the score as three warning events. Recent Violations interleaves blocked requests and compliance events sorted by timestamp, with severity-aware row rendering.
Metrics
A Prometheus / OpenTelemetry counter is exposed on the/metrics endpoint:
aistudio_llm_requests_total to get a per-request rate.
See Analytics & Monitoring for the full metric catalog.
Suggested Event-Type Conventions
event_type is free-form, but consistency across filters makes dashboards and queries much more useful. Conventions used by the bundled filter scripts:
For
metadata keys, prefer:
matched_pattern(string): the substring or regex match that fired the event.redacted_types(array of strings): categories of PII or content removed.
Migration Notes
- Schema: v2.1 GORM auto-migration creates the
compliance_eventstable on first startup. No manual step required. - Filter scripts written for v2.0 are forward-compatible. The
compliance_eventsfield is optional and ignored if absent. - Bundled filter library: the ship-with scripts (PII redaction, content blocking, response guardrails) were updated in v2.1 to emit compliance events with the conventions above. Re-import them from the marketplace, or copy from the updated templates in the admin UI, if you want them out of the box.
- Custom analytics handlers: the
AnalyticsHandlerinterface now takescontext.Contexton its recording methods, including the newRecordComplianceEvents. Custom implementations need to update their signatures;RecordComplianceEventscan be a no-op if you do not consume compliance events.
See Also
- Filters: script-level syntax and examples.
- Analytics & Monitoring: the surrounding analytics pipeline and the full metric catalog.
- Edge Gateway: hub-spoke architecture and the analytics pulse that carries edge events to control.
- Tyk AI Studio release notes: the
AnalyticsHandlercontext change and related v2.1.0 SDK updates.