Skip to content

GuardrailUsage dataclass

The details on the use of the guardrail.

Source code in src/aws_sdk_bedrock_runtime/models.py
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
@dataclass(kw_only=True)
class GuardrailUsage:
    """The details on the use of the guardrail."""

    topic_policy_units: int
    """The topic policy units processed by the guardrail."""

    content_policy_units: int
    """The content policy units processed by the guardrail."""

    word_policy_units: int
    """The word policy units processed by the guardrail."""

    sensitive_information_policy_units: int
    """The sensitive information policy units processed by the guardrail."""

    sensitive_information_policy_free_units: int
    """The sensitive information policy free units processed by the guardrail."""

    contextual_grounding_policy_units: int
    """The contextual grounding policy units processed by the guardrail."""

    content_policy_image_units: int | None = None
    """The content policy image units processed by the guardrail."""

    automated_reasoning_policy_units: int | None = None
    """The number of text units processed by the automated reasoning policy."""

    automated_reasoning_policies: int | None = None
    """The number of automated reasoning policies that were processed during
    the guardrail evaluation.
    """

    def serialize(self, serializer: ShapeSerializer):
        serializer.write_struct(_SCHEMA_GUARDRAIL_USAGE, self)

    def serialize_members(self, serializer: ShapeSerializer):
        serializer.write_integer(
            _SCHEMA_GUARDRAIL_USAGE.members["topicPolicyUnits"], self.topic_policy_units
        )
        serializer.write_integer(
            _SCHEMA_GUARDRAIL_USAGE.members["contentPolicyUnits"],
            self.content_policy_units,
        )
        serializer.write_integer(
            _SCHEMA_GUARDRAIL_USAGE.members["wordPolicyUnits"], self.word_policy_units
        )
        serializer.write_integer(
            _SCHEMA_GUARDRAIL_USAGE.members["sensitiveInformationPolicyUnits"],
            self.sensitive_information_policy_units,
        )
        serializer.write_integer(
            _SCHEMA_GUARDRAIL_USAGE.members["sensitiveInformationPolicyFreeUnits"],
            self.sensitive_information_policy_free_units,
        )
        serializer.write_integer(
            _SCHEMA_GUARDRAIL_USAGE.members["contextualGroundingPolicyUnits"],
            self.contextual_grounding_policy_units,
        )
        if self.content_policy_image_units is not None:
            serializer.write_integer(
                _SCHEMA_GUARDRAIL_USAGE.members["contentPolicyImageUnits"],
                self.content_policy_image_units,
            )

        if self.automated_reasoning_policy_units is not None:
            serializer.write_integer(
                _SCHEMA_GUARDRAIL_USAGE.members["automatedReasoningPolicyUnits"],
                self.automated_reasoning_policy_units,
            )

        if self.automated_reasoning_policies is not None:
            serializer.write_integer(
                _SCHEMA_GUARDRAIL_USAGE.members["automatedReasoningPolicies"],
                self.automated_reasoning_policies,
            )

    @classmethod
    def deserialize(cls, deserializer: ShapeDeserializer) -> Self:
        return cls(**cls.deserialize_kwargs(deserializer))

    @classmethod
    def deserialize_kwargs(cls, deserializer: ShapeDeserializer) -> dict[str, Any]:
        kwargs: dict[str, Any] = {}

        def _consumer(schema: Schema, de: ShapeDeserializer) -> None:
            match schema.expect_member_index():
                case 0:
                    kwargs["topic_policy_units"] = de.read_integer(
                        _SCHEMA_GUARDRAIL_USAGE.members["topicPolicyUnits"]
                    )

                case 1:
                    kwargs["content_policy_units"] = de.read_integer(
                        _SCHEMA_GUARDRAIL_USAGE.members["contentPolicyUnits"]
                    )

                case 2:
                    kwargs["word_policy_units"] = de.read_integer(
                        _SCHEMA_GUARDRAIL_USAGE.members["wordPolicyUnits"]
                    )

                case 3:
                    kwargs["sensitive_information_policy_units"] = de.read_integer(
                        _SCHEMA_GUARDRAIL_USAGE.members[
                            "sensitiveInformationPolicyUnits"
                        ]
                    )

                case 4:
                    kwargs["sensitive_information_policy_free_units"] = de.read_integer(
                        _SCHEMA_GUARDRAIL_USAGE.members[
                            "sensitiveInformationPolicyFreeUnits"
                        ]
                    )

                case 5:
                    kwargs["contextual_grounding_policy_units"] = de.read_integer(
                        _SCHEMA_GUARDRAIL_USAGE.members[
                            "contextualGroundingPolicyUnits"
                        ]
                    )

                case 6:
                    kwargs["content_policy_image_units"] = de.read_integer(
                        _SCHEMA_GUARDRAIL_USAGE.members["contentPolicyImageUnits"]
                    )

                case 7:
                    kwargs["automated_reasoning_policy_units"] = de.read_integer(
                        _SCHEMA_GUARDRAIL_USAGE.members["automatedReasoningPolicyUnits"]
                    )

                case 8:
                    kwargs["automated_reasoning_policies"] = de.read_integer(
                        _SCHEMA_GUARDRAIL_USAGE.members["automatedReasoningPolicies"]
                    )

                case _:
                    logger.debug("Unexpected member schema: %s", schema)

        deserializer.read_struct(_SCHEMA_GUARDRAIL_USAGE, consumer=_consumer)
        return kwargs

Attributes

automated_reasoning_policies class-attribute instance-attribute

automated_reasoning_policies: int | None = None

The number of automated reasoning policies that were processed during the guardrail evaluation.

automated_reasoning_policy_units class-attribute instance-attribute

automated_reasoning_policy_units: int | None = None

The number of text units processed by the automated reasoning policy.

content_policy_image_units class-attribute instance-attribute

content_policy_image_units: int | None = None

The content policy image units processed by the guardrail.

content_policy_units instance-attribute

content_policy_units: int

The content policy units processed by the guardrail.

contextual_grounding_policy_units instance-attribute

contextual_grounding_policy_units: int

The contextual grounding policy units processed by the guardrail.

sensitive_information_policy_free_units instance-attribute

sensitive_information_policy_free_units: int

The sensitive information policy free units processed by the guardrail.

sensitive_information_policy_units instance-attribute

sensitive_information_policy_units: int

The sensitive information policy units processed by the guardrail.

topic_policy_units instance-attribute

topic_policy_units: int

The topic policy units processed by the guardrail.

word_policy_units instance-attribute

word_policy_units: int

The word policy units processed by the guardrail.