Skip to content

GuardrailCustomWord dataclass

A custom word configured in a guardrail.

Source code in src/aws_sdk_bedrock_runtime/models.py
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
@dataclass(kw_only=True)
class GuardrailCustomWord:
    """A custom word configured in a guardrail."""

    match: str
    """The match for the custom word."""

    action: str
    """The action for the custom word."""

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

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

    def serialize_members(self, serializer: ShapeSerializer):
        serializer.write_string(
            _SCHEMA_GUARDRAIL_CUSTOM_WORD.members["match"], self.match
        )
        serializer.write_string(
            _SCHEMA_GUARDRAIL_CUSTOM_WORD.members["action"], self.action
        )
        if self.detected is not None:
            serializer.write_boolean(
                _SCHEMA_GUARDRAIL_CUSTOM_WORD.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["match"] = de.read_string(
                        _SCHEMA_GUARDRAIL_CUSTOM_WORD.members["match"]
                    )

                case 1:
                    kwargs["action"] = de.read_string(
                        _SCHEMA_GUARDRAIL_CUSTOM_WORD.members["action"]
                    )

                case 2:
                    kwargs["detected"] = de.read_boolean(
                        _SCHEMA_GUARDRAIL_CUSTOM_WORD.members["detected"]
                    )

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

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

Attributes

action instance-attribute

action: str

The action for the custom word.

detected class-attribute instance-attribute

detected: bool | None = None

Indicates whether custom word content that breaches the guardrail configuration is detected.

match instance-attribute

match: str

The match for the custom word.