Skip to content

GuardrailContextualGroundingFilter dataclass

The details for the guardrails contextual grounding filter.

Source code in src/aws_sdk_bedrock_runtime/models.py
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
@dataclass(kw_only=True)
class GuardrailContextualGroundingFilter:
    """The details for the guardrails contextual grounding filter."""

    type: str
    """The contextual grounding filter type."""

    threshold: float
    """The threshold used by contextual grounding filter to determine whether
    the content is grounded or not.
    """

    score: float
    """The score generated by contextual grounding filter."""

    action: str
    """The action performed by the guardrails contextual grounding filter."""

    detected: bool | None = None
    """Indicates whether content that fails the contextual grounding evaluation
    (grounding or relevance score less than the corresponding threshold) was
    detected.
    """

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

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

                case 1:
                    kwargs["threshold"] = de.read_double(
                        _SCHEMA_GUARDRAIL_CONTEXTUAL_GROUNDING_FILTER.members[
                            "threshold"
                        ]
                    )

                case 2:
                    kwargs["score"] = de.read_double(
                        _SCHEMA_GUARDRAIL_CONTEXTUAL_GROUNDING_FILTER.members["score"]
                    )

                case 3:
                    kwargs["action"] = de.read_string(
                        _SCHEMA_GUARDRAIL_CONTEXTUAL_GROUNDING_FILTER.members["action"]
                    )

                case 4:
                    kwargs["detected"] = de.read_boolean(
                        _SCHEMA_GUARDRAIL_CONTEXTUAL_GROUNDING_FILTER.members[
                            "detected"
                        ]
                    )

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

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

Attributes

action instance-attribute

action: str

The action performed by the guardrails contextual grounding filter.

detected class-attribute instance-attribute

detected: bool | None = None

Indicates whether content that fails the contextual grounding evaluation (grounding or relevance score less than the corresponding threshold) was detected.

score instance-attribute

score: float

The score generated by contextual grounding filter.

threshold instance-attribute

threshold: float

The threshold used by contextual grounding filter to determine whether the content is grounded or not.

type instance-attribute

type: str

The contextual grounding filter type.