Skip to content

GuardrailImageBlock dataclass

Contain an image which user wants guarded. This block is accepted by the guardrails independent API.

Source code in src/aws_sdk_bedrock_runtime/models.py
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
@dataclass(kw_only=True)
class GuardrailImageBlock:
    """Contain an image which user wants guarded. This block is accepted by the
    guardrails independent API.
    """

    format: str
    """The format details for the file type of the image blocked by the
    guardrail.
    """

    source: GuardrailImageSource = field(repr=False)
    """The image source (image bytes) details of the image blocked by the
    guardrail.
    """

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

    def serialize_members(self, serializer: ShapeSerializer):
        serializer.write_string(
            _SCHEMA_GUARDRAIL_IMAGE_BLOCK.members["format"], self.format
        )
        serializer.write_struct(
            _SCHEMA_GUARDRAIL_IMAGE_BLOCK.members["source"], self.source
        )

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

                case 1:
                    kwargs["source"] = _GuardrailImageSourceDeserializer().deserialize(
                        de
                    )

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

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

Attributes

format instance-attribute

format: str

The format details for the file type of the image blocked by the guardrail.

source class-attribute instance-attribute

source: GuardrailImageSource = field(repr=False)

The image source (image bytes) details of the image blocked by the guardrail.