Skip to content

DocumentBlock dataclass

A document to include in a message.

Source code in src/aws_sdk_bedrock_runtime/models.py
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
@dataclass(kw_only=True)
class DocumentBlock:
    """A document to include in a message."""

    name: str
    """A name for the document. The name can only contain the following
    characters:

    - Alphanumeric characters

    - Whitespace characters (no more than one in a row)

    - Hyphens

    - Parentheses

    - Square brackets

    Note:
        This field is vulnerable to prompt injections, because the model might
        inadvertently interpret it as instructions. Therefore, we recommend that
        you specify a neutral name.
    """

    source: DocumentSource
    """Contains the content of the document."""

    format: str = "txt"
    """The format of a document, or its extension."""

    context: str | None = None
    """Contextual information about how the document should be processed or
    interpreted by the model when generating citations.
    """

    citations: CitationsConfig | None = None
    """Configuration settings that control how citations should be generated
    for this specific document.
    """

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

    def serialize_members(self, serializer: ShapeSerializer):
        serializer.write_string(_SCHEMA_DOCUMENT_BLOCK.members["format"], self.format)
        serializer.write_string(_SCHEMA_DOCUMENT_BLOCK.members["name"], self.name)
        serializer.write_struct(_SCHEMA_DOCUMENT_BLOCK.members["source"], self.source)
        if self.context is not None:
            serializer.write_string(
                _SCHEMA_DOCUMENT_BLOCK.members["context"], self.context
            )

        if self.citations is not None:
            serializer.write_struct(
                _SCHEMA_DOCUMENT_BLOCK.members["citations"], self.citations
            )

    @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_DOCUMENT_BLOCK.members["format"]
                    )

                case 1:
                    kwargs["name"] = de.read_string(
                        _SCHEMA_DOCUMENT_BLOCK.members["name"]
                    )

                case 2:
                    kwargs["source"] = _DocumentSourceDeserializer().deserialize(de)

                case 3:
                    kwargs["context"] = de.read_string(
                        _SCHEMA_DOCUMENT_BLOCK.members["context"]
                    )

                case 4:
                    kwargs["citations"] = CitationsConfig.deserialize(de)

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

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

Attributes

citations class-attribute instance-attribute

citations: CitationsConfig | None = None

Configuration settings that control how citations should be generated for this specific document.

context class-attribute instance-attribute

context: str | None = None

Contextual information about how the document should be processed or interpreted by the model when generating citations.

format class-attribute instance-attribute

format: str = 'txt'

The format of a document, or its extension.

name instance-attribute

name: str

A name for the document. The name can only contain the following characters:

  • Alphanumeric characters

  • Whitespace characters (no more than one in a row)

  • Hyphens

  • Parentheses

  • Square brackets

Note

This field is vulnerable to prompt injections, because the model might inadvertently interpret it as instructions. Therefore, we recommend that you specify a neutral name.

source instance-attribute

Contains the content of the document.