Skip to main content

Distribution queries

Aggregated snapshots of guardrail evaluations over a time window. Every example below posts JSON to:
POST https://{your_control_plane_url}/api/svc/v1/llm-gateway/metrics/query
with Authorization: Bearer <your_api_key> and Content-Type: application/json. To keep the snippets short, only the JSON body is shown; the wrapper is identical to the Overview Quick Start.
Counts grouped by guardrail and outcome, useful for spotting guardrails that fail most often:
json={
    "startTs": "2026-04-21T00:00:00.000Z",
    "endTs": "2026-04-22T00:00:00.000Z",
    "datasource": "guardrailMetrics",
    "type": "distribution",
    "aggregations": [
        {"type": "count", "column": "guardrailName"}
    ],
    "groupBy": ["guardrailName", "guardrailResult"]
}
p50, p90, and p99 grouped by guardrail, restricted to output-scope evaluations:
json={
    "startTs": "2026-04-21T00:00:00.000Z",
    "endTs": "2026-04-22T00:00:00.000Z",
    "datasource": "guardrailMetrics",
    "type": "distribution",
    "aggregations": [
        {"type": "p50", "column": "latencyMs"},
        {"type": "p90", "column": "latencyMs"},
        {"type": "p99", "column": "latencyMs"}
    ],
    "groupBy": ["guardrailName"],
    "filters": [
        {"fieldName": "appliedOnEntityScope", "operator": "IN", "value": ["output"]}
    ]
}
Volume and average latency of evaluations slower than 500 ms, grouped by guardrail:
json={
    "startTs": "2026-04-21T00:00:00.000Z",
    "endTs": "2026-04-22T00:00:00.000Z",
    "datasource": "guardrailMetrics",
    "type": "distribution",
    "aggregations": [
        {"type": "count", "column": "guardrailName"},
        {"type": "avg", "column": "latencyMs"}
    ],
    "groupBy": ["guardrailName"],
    "filters": [
        {"fieldName": "latencyMs", "operator": "GREATER_THAN", "value": 500}
    ]
}
Restrict to failed evaluations, grouped by guardrail and scope:
json={
    "startTs": "2026-04-21T00:00:00.000Z",
    "endTs": "2026-04-22T00:00:00.000Z",
    "datasource": "guardrailMetrics",
    "type": "distribution",
    "aggregations": [
        {"type": "count", "column": "guardrailName"}
    ],
    "groupBy": ["guardrailName", "appliedOnEntityScope"],
    "filters": [
        {"fieldName": "guardrailResult", "operator": "IN", "value": ["fail"]}
    ]
}
Counts by team and a custom metadata key, restricted via team array filter:
json={
    "startTs": "2026-04-21T00:00:00.000Z",
    "endTs": "2026-04-22T00:00:00.000Z",
    "datasource": "guardrailMetrics",
    "type": "distribution",
    "aggregations": [
        {"type": "count", "column": "guardrailName"}
    ],
    "groupBy": ["team", "metadata.environment"],
    "filters": [
        {"fieldName": "team", "operator": "ARRAY_HAS_ANY", "value": ["team-alpha", "team-beta"]}
    ]
}
How many unique guardrails ran on input vs output:
json={
    "startTs": "2026-04-21T00:00:00.000Z",
    "endTs": "2026-04-22T00:00:00.000Z",
    "datasource": "guardrailMetrics",
    "type": "distribution",
    "aggregations": [
        {"type": "countDistinct", "column": "guardrailName"}
    ],
    "groupBy": ["appliedOnEntityScope"]
}
Use IN on guardrailName to focus on a subset:
json={
    "startTs": "2026-04-21T00:00:00.000Z",
    "endTs": "2026-04-22T00:00:00.000Z",
    "datasource": "guardrailMetrics",
    "type": "distribution",
    "aggregations": [
        {"type": "count", "column": "guardrailName"},
        {"type": "p99", "column": "latencyMs"}
    ],
    "groupBy": ["guardrailName", "guardrailResult"],
    "filters": [
        {"fieldName": "guardrailName", "operator": "IN", "value": ["pii-detector", "toxicity-filter"]}
    ]
}