api7 / api7/aisix

guardrail metrics: cover the /v1/messages (anthropic) path

Open
#519 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug priority-normal
Dominant language
Rust
Stars
157
Forks
32
Avg merge
1h 25m
Merged PRs (30d)
145

Description

The guardrail outcome counters added in the test-connection observability work (aisix_guardrail_blocks_total / aisix_guardrail_bypasses_total) are recorded in chat.rs's centralized emit_usage_event, which covers /v1/chat/completions only.

The anthropic /v1/messages handler (messages.rs) ALSO runs the guardrail chain (resolve + check_input/check_output, returns ContentFiltered on block) but has a pre-existing telemetry gap: its UsageEvent / AnthropicStreamCompletion does not carry guardrail_blocked / bypass_reason, so the metric can't be recorded at its emit point. As a result the counters undercount anthropic guardrail blocks/bypasses.

Fix: thread guardrail_blocked + bypass_reason through the messages.rs telemetry (closing the AnthropicStreamCompletion gap) and record_guardrail_outcome at its emit, OR record at the messages verdict sites. This naturally folds into the applied-guardrails telemetry-threading work (#379 observability "A" slice), which reworks guardrail telemetry uniformly across both paths.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with chat.rs's centralized emit_usage_event and compare it with the /v1/messages handler in messages.rs, including UsageEvent and AnthropicStreamCompletion. Trace where guardrail resolve, check_input/check_output, and ContentFiltered verdicts are produced, then follow the telemetry-threading work in #379. Done means anthropic guardrail blocks and bypasses reach record_guardrail_outcome and the counters no longer undercount that path.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api, observability
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.