Skip to main content
Every guarded request writes one row to the security_events table (input and output are separate rows). Self-hosted deployments own that Postgres database directly, so you can point psql, a BI tool, or your warehouse’s foreign-data wrapper at it and run these recipes as-is. On PromptGuard Cloud, pull the same data through the Interactions API and load it into your own store.
There is no pre-aggregated roll-up table today: these recipes run directly against the raw security_events (and, for configuration/auth activity, audit_events) event tables. The Daily and hourly roll-ups section shows how to build your own materialized view if you want cheaper dashboards.

The tables you’ll query

security_events: the request log

One row per policy evaluation. The columns that matter for analytics:
security_events is retention-bounded. Rows are purged on a per-plan schedule (Free 24h, Developer 30d, Enterprise 90d / custom). A query over a 90-day window on a Developer plan returns at most 30 days of rows. For durable analytics, raise your retention (Enterprise custom_retention_days) or stream events into your own warehouse. audit_events is never purged.

audit_events: the compliance trail

Configuration changes, authentication, and data access. Hash-chained and never purged. Columns: created_at, organization_id, user_id, event_type, category (security | authentication | data_access | configuration | billing), action, outcome (success | failure | denied | error), resource_type, resource_id, ip_address, details (jsonb).

Latency percentiles

Engine processing time by percentile over the last 24 hours. Use percentile_cont for interpolated percentiles.
Break the same percentiles down by surface to compare the developer proxy against Shadow AI scans:
processing_time_ms is the time PromptGuard’s engine spent, not end-to-end request time. On the proxy path it excludes the upstream provider call. See Latency Budgets for what each detector contributes.

Token volume by model

Grouped by upstream model. Tokens are NULL on /guard-only scans (they never call a provider), so filter them out.
These are token counts, not dollars. For dollars, use upstream_cost_usd in the next recipe. PromptGuard’s earlier cost_usd_estimate was tokens multiplied by a price table maintained by hand, and it drifted, one model carried a price 7.5× its real rate for months, and nothing detected it, because a wrong price looks exactly like a right one. The table behind upstream_cost_usd is one versioned file whose every rate is dated, sourced to the vendor’s own pricing page and checked against a second published price list, and a call it cannot price exactly is NULL with a reason rather than a guess.Token counts come from the provider’s own usage block, so they cannot go stale.

Upstream spend by model

What your providers will charge at list price, by the model that answered. The second figure is how much traffic the table could not price, so a total is never read as complete when it is not.
cost_basis IS NOT NULL selects the events that were costed: one per upstream response, so the sum counts each call once even when its response logged several output rows. Every response your provider billed has exactly one costed event, and that event also carries the call’s tokens_input and tokens_output; the call’s other output rows carry neither, so summing tokens counts each call once too. When an output scan wrote an event, that event is the costed one. When none did, PromptGuard writes a usage-only output event: decision is allow, threat_type is NULL, and event_metadata.usage_only says why there was no scan: A usage-only event is not a request, a finding or a check: the dashboard leaves it out of every request count, detection rate, risk band and latency figure, and keeps its tokens and cost in every sum. To do the same in your own queries, add AND NOT event_metadata ? 'usage_only' when counting requests, and leave it off when summing tokens or cost. To list them: WHERE event_metadata ? 'usage_only'.
OpenAI streams report usage only when asked with stream_options: {"include_usage": true}. When you do not set it, PromptGuard asks for you on OpenAI, DeepSeek, Groq, Ollama and vLLM, and removes the extra usage chunk before the stream reaches you, so your stream is unchanged. When you set it to false, PromptGuard respects that: the stream reports no usage and is recorded as no_usage. Other providers either report stream usage unasked or would refuse the field. Azure OpenAI is not asked: the API version PromptGuard pins predates the field. Gemini and Cohere calls record their tokens and are unpriced_model, with no figure. Your provider’s billing console is the complete figure.
Token volume attributed to blocked requests (the calls you avoided sending, plus those redacted and still forwarded):

High-risk activity by attribution label

Ranks traffic by blocked-request volume, grouped by end_user_id.
Group by the label or by the account, never by both in one column. end_user_id is an attribution label, free text a caller or a device supplies, and user_id is the account that owns the events. Coalescing them produces a column where a proven account and an unvalidated hostname are indistinguishable, which is exactly the reading the product refuses to offer. Rows with a NULL end_user_id are traffic nobody was attributed to; count them, do not fill them in with the account.
Drill into a single label’s most recent blocks, including the threat type and detector that fired:

Blocked over time

Hourly blocked-vs-total counts for a time-series chart:
Swap date_trunc('hour', …) for date_trunc('day', …) and widen the interval for a daily trend.

Threats by detector

decision/threat_type tell you what was caught; the detector that caught it lives in event_metadata->>'detector' (values include regex, ml, agentic, and specific detector names). This recipe attributes blocks to the detection layer that fired, useful for tuning which layers earn their latency.
Threat mix by surface (are Shadow AI pastes producing different threats than the developer proxy?):

Daily and hourly roll-ups

There is no roll-up table shipped, so long-window dashboards scan raw events every load. If that gets expensive, materialize a daily summary yourself. This view is safe to REFRESH on a schedule (nightly, or hourly with CONCURRENTLY):
Refresh it:
Because security_events is retention-bounded, a materialized view built from it inherits the same horizon, refreshing after a purge drops the aged-out days. To keep history beyond your plan’s retention, INSERT each day’s roll-up into a plain table you own (self-host) or into your warehouse (Cloud) before the source rows are purged, rather than relying on the view alone.
An INSERT-based accumulator that survives purges:
Schedule that with pg_cron (self-host / Supabase) or any external scheduler:

Audit trail (configuration & auth)

Config changes and authentication live in audit_events, not security_events. Recent denied or failed sensitive actions:

Next steps

Latency Budgets

Per-detector p99 budgets behind processing_time_ms

Audit Logs

Export the same data through the Interactions API

Usage Tracking

Plan quotas, request counts, and spend

Dashboard

Prebuilt analytics in the app
Last modified on November 8, 2026