Skip to content

GuardrailStreamConfiguration dataclass

Configuration information for a guardrail that you use with the ConverseStream action.

Source code in src/aws_sdk_bedrock_runtime/models.py
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
@dataclass(kw_only=True)
class GuardrailStreamConfiguration:
    """Configuration information for a guardrail that you use with the
    [ConverseStream](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ConverseStream.html)
    action.
    """

    guardrail_identifier: str
    """The identifier for the guardrail."""

    guardrail_version: str
    """The version of the guardrail."""

    trace: str = "disabled"
    """The trace behavior for the guardrail."""

    stream_processing_mode: str = "sync"
    """The processing mode.

    The processing mode. For more information, see *Configure streaming
    response behavior* in the *Amazon Bedrock User Guide*.
    """

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

    def serialize_members(self, serializer: ShapeSerializer):
        serializer.write_string(
            _SCHEMA_GUARDRAIL_STREAM_CONFIGURATION.members["guardrailIdentifier"],
            self.guardrail_identifier,
        )
        serializer.write_string(
            _SCHEMA_GUARDRAIL_STREAM_CONFIGURATION.members["guardrailVersion"],
            self.guardrail_version,
        )
        serializer.write_string(
            _SCHEMA_GUARDRAIL_STREAM_CONFIGURATION.members["trace"], self.trace
        )
        serializer.write_string(
            _SCHEMA_GUARDRAIL_STREAM_CONFIGURATION.members["streamProcessingMode"],
            self.stream_processing_mode,
        )

    @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["guardrail_identifier"] = de.read_string(
                        _SCHEMA_GUARDRAIL_STREAM_CONFIGURATION.members[
                            "guardrailIdentifier"
                        ]
                    )

                case 1:
                    kwargs["guardrail_version"] = de.read_string(
                        _SCHEMA_GUARDRAIL_STREAM_CONFIGURATION.members[
                            "guardrailVersion"
                        ]
                    )

                case 2:
                    kwargs["trace"] = de.read_string(
                        _SCHEMA_GUARDRAIL_STREAM_CONFIGURATION.members["trace"]
                    )

                case 3:
                    kwargs["stream_processing_mode"] = de.read_string(
                        _SCHEMA_GUARDRAIL_STREAM_CONFIGURATION.members[
                            "streamProcessingMode"
                        ]
                    )

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

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

Attributes

guardrail_identifier instance-attribute

guardrail_identifier: str

The identifier for the guardrail.

guardrail_version instance-attribute

guardrail_version: str

The version of the guardrail.

stream_processing_mode class-attribute instance-attribute

stream_processing_mode: str = 'sync'

The processing mode.

The processing mode. For more information, see Configure streaming response behavior in the Amazon Bedrock User Guide.

trace class-attribute instance-attribute

trace: str = 'disabled'

The trace behavior for the guardrail.