Skip to content

馃悰 Bug Report: gen_ai.bedrock.guardrail.activation counts every Bedrock call聽#4471

Description

@AnoshanJ

Component: Bedrock Instrumentation

馃摐 Description

is_guardrail_activated() in guardrail.py ends with:

return response.get("amazon-bedrock-guardrailAction") != "NONE"

When no guardrail is configured, Bedrock omits that key, so .get() returns None and None != "NONE" is True. Every ordinary response is treated as a guardrail activation, and gen_ai.bedrock.guardrail.activation is incremented on every Bedrock call.

Defaulting the key fixes it: response.get("amazon-bedrock-guardrailAction", "NONE") != "NONE".

馃憻 Reproduction steps

from opentelemetry.instrumentation.bedrock.guardrail import is_guardrail_activated

print(is_guardrail_activated({"stopReason": "end_turn"}))  # True, expected False

馃憤 Expected behavior

A response with no amazon-bedrock-guardrailAction key is not an activation.

馃憥 Actual Behavior

It counts as one, so the metric reports activations for users with no guardrails configured.

馃 Python Version

3.12

馃搩 Additional context

The same line crashes when metrics are disabled, since _instrument() sets the counters to None but guardrail.py dereferences them unconditionally:

guardrail.py", line 179, in guardrail_converse
    metric_params.guardrail_activation.add(1, attrs)
AttributeError: 'NoneType' object has no attribute 'add'

Present from 0.39.0 through 0.62.3.

馃憖 Duplicate check

Checked, no existing issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions