Skip to content

GuardrailTraceAssessment dataclass

A Top level guardrail trace object. For more information, see ConverseTrace.

Source code in src/aws_sdk_bedrock_runtime/models.py
 9915
 9916
 9917
 9918
 9919
 9920
 9921
 9922
 9923
 9924
 9925
 9926
 9927
 9928
 9929
 9930
 9931
 9932
 9933
 9934
 9935
 9936
 9937
 9938
 9939
 9940
 9941
 9942
 9943
 9944
 9945
 9946
 9947
 9948
 9949
 9950
 9951
 9952
 9953
 9954
 9955
 9956
 9957
 9958
 9959
 9960
 9961
 9962
 9963
 9964
 9965
 9966
 9967
 9968
 9969
 9970
 9971
 9972
 9973
 9974
 9975
 9976
 9977
 9978
 9979
 9980
 9981
 9982
 9983
 9984
 9985
 9986
 9987
 9988
 9989
 9990
 9991
 9992
 9993
 9994
 9995
 9996
 9997
 9998
 9999
10000
10001
10002
10003
10004
10005
10006
@dataclass(kw_only=True)
class GuardrailTraceAssessment:
    """A Top level guardrail trace object. For more information, see
    [ConverseTrace](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ConverseTrace.html).
    """

    model_output: list[str] | None = None
    """The output from the model."""

    input_assessment: dict[str, GuardrailAssessment] | None = None
    """The input assessment."""

    output_assessments: dict[str, list[GuardrailAssessment]] | None = None
    """the output assessments."""

    action_reason: str | None = None
    """Provides the reason for the action taken when harmful content is
    detected.
    """

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

    def serialize_members(self, serializer: ShapeSerializer):
        if self.model_output is not None:
            _serialize_model_outputs(
                serializer,
                _SCHEMA_GUARDRAIL_TRACE_ASSESSMENT.members["modelOutput"],
                self.model_output,
            )

        if self.input_assessment is not None:
            _serialize_guardrail_assessment_map(
                serializer,
                _SCHEMA_GUARDRAIL_TRACE_ASSESSMENT.members["inputAssessment"],
                self.input_assessment,
            )

        if self.output_assessments is not None:
            _serialize_guardrail_assessment_list_map(
                serializer,
                _SCHEMA_GUARDRAIL_TRACE_ASSESSMENT.members["outputAssessments"],
                self.output_assessments,
            )

        if self.action_reason is not None:
            serializer.write_string(
                _SCHEMA_GUARDRAIL_TRACE_ASSESSMENT.members["actionReason"],
                self.action_reason,
            )

    @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["model_output"] = _deserialize_model_outputs(
                        de, _SCHEMA_GUARDRAIL_TRACE_ASSESSMENT.members["modelOutput"]
                    )

                case 1:
                    kwargs["input_assessment"] = _deserialize_guardrail_assessment_map(
                        de,
                        _SCHEMA_GUARDRAIL_TRACE_ASSESSMENT.members["inputAssessment"],
                    )

                case 2:
                    kwargs["output_assessments"] = (
                        _deserialize_guardrail_assessment_list_map(
                            de,
                            _SCHEMA_GUARDRAIL_TRACE_ASSESSMENT.members[
                                "outputAssessments"
                            ],
                        )
                    )

                case 3:
                    kwargs["action_reason"] = de.read_string(
                        _SCHEMA_GUARDRAIL_TRACE_ASSESSMENT.members["actionReason"]
                    )

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

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

Attributes

action_reason class-attribute instance-attribute

action_reason: str | None = None

Provides the reason for the action taken when harmful content is detected.

input_assessment class-attribute instance-attribute

input_assessment: dict[str, GuardrailAssessment] | None = None

The input assessment.

model_output class-attribute instance-attribute

model_output: list[str] | None = None

The output from the model.

output_assessments class-attribute instance-attribute

output_assessments: dict[str, list[GuardrailAssessment]] | None = None

the output assessments.