Skip to content

GuardrailTopic dataclass

Information about a topic guardrail.

Source code in src/aws_sdk_bedrock_runtime/models.py
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
@dataclass(kw_only=True)
class GuardrailTopic:
    """Information about a topic guardrail."""

    name: str
    """The name for the guardrail."""

    type: str
    """The type behavior that the guardrail should perform when the model
    detects the topic.
    """

    action: str
    """The action the guardrail should take when it intervenes on a topic."""

    detected: bool | None = None
    """Indicates whether topic content that breaches the guardrail
    configuration is detected.
    """

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

    def serialize_members(self, serializer: ShapeSerializer):
        serializer.write_string(_SCHEMA_GUARDRAIL_TOPIC.members["name"], self.name)
        serializer.write_string(_SCHEMA_GUARDRAIL_TOPIC.members["type"], self.type)
        serializer.write_string(_SCHEMA_GUARDRAIL_TOPIC.members["action"], self.action)
        if self.detected is not None:
            serializer.write_boolean(
                _SCHEMA_GUARDRAIL_TOPIC.members["detected"], self.detected
            )

    @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["name"] = de.read_string(
                        _SCHEMA_GUARDRAIL_TOPIC.members["name"]
                    )

                case 1:
                    kwargs["type"] = de.read_string(
                        _SCHEMA_GUARDRAIL_TOPIC.members["type"]
                    )

                case 2:
                    kwargs["action"] = de.read_string(
                        _SCHEMA_GUARDRAIL_TOPIC.members["action"]
                    )

                case 3:
                    kwargs["detected"] = de.read_boolean(
                        _SCHEMA_GUARDRAIL_TOPIC.members["detected"]
                    )

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

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

Attributes

action instance-attribute

action: str

The action the guardrail should take when it intervenes on a topic.

detected class-attribute instance-attribute

detected: bool | None = None

Indicates whether topic content that breaches the guardrail configuration is detected.

name instance-attribute

name: str

The name for the guardrail.

type instance-attribute

type: str

The type behavior that the guardrail should perform when the model detects the topic.