Bug Report: gen_ai.bedrock.guardrail.activation counts every Bedrock call

Author: AnoshanJCreated Sep 15, 2026Updated Sep 15, 2026

Component: Bedrock Instrumentation

Description

is_guardrail_activated() in guardrail.py ends with:

python
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

python
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.