Amazon Bedrock Runtime

2024/07/10 - Amazon Bedrock Runtime - 1 new2 updated api methods

Changes  Add support for contextual grounding check for Guardrails for Amazon Bedrock.

ApplyGuardrail (new) Link ¶

The action to apply a guardrail.

See also: AWS API Documentation

Request Syntax

client.apply_guardrail(
    guardrailIdentifier='string',
    guardrailVersion='string',
    source='INPUT'|'OUTPUT',
    content=[
        {
            'text': {
                'text': 'string',
                'qualifiers': [
                    'grounding_source'|'query'|'guard_content',
                ]
            }
        },
    ]
)
type guardrailIdentifier:

string

param guardrailIdentifier:

[REQUIRED]

The guardrail identifier used in the request to apply the guardrail.

type guardrailVersion:

string

param guardrailVersion:

[REQUIRED]

The guardrail version used in the request to apply the guardrail.

type source:

string

param source:

[REQUIRED]

The source of data used in the request to apply the guardrail.

type content:

list

param content:

[REQUIRED]

The content details used in the request to apply the guardrail.

  • (dict) --

    The content block to be evaluated by the guardrail.

    • text (dict) --

      Text within content block to be evaluated by the guardrail.

      • text (string) -- [REQUIRED]

        The input text details to be evaluated by the guardrail.

      • qualifiers (list) --

        The qualifiers describing the text block.

        • (string) --

rtype:

dict

returns:

Response Syntax

{
    'usage': {
        'topicPolicyUnits': 123,
        'contentPolicyUnits': 123,
        'wordPolicyUnits': 123,
        'sensitiveInformationPolicyUnits': 123,
        'sensitiveInformationPolicyFreeUnits': 123,
        'contextualGroundingPolicyUnits': 123
    },
    'action': 'NONE'|'GUARDRAIL_INTERVENED',
    'outputs': [
        {
            'text': 'string'
        },
    ],
    'assessments': [
        {
            'topicPolicy': {
                'topics': [
                    {
                        'name': 'string',
                        'type': 'DENY',
                        'action': 'BLOCKED'
                    },
                ]
            },
            'contentPolicy': {
                'filters': [
                    {
                        'type': 'INSULTS'|'HATE'|'SEXUAL'|'VIOLENCE'|'MISCONDUCT'|'PROMPT_ATTACK',
                        'confidence': 'NONE'|'LOW'|'MEDIUM'|'HIGH',
                        'action': 'BLOCKED'
                    },
                ]
            },
            'wordPolicy': {
                'customWords': [
                    {
                        'match': 'string',
                        'action': 'BLOCKED'
                    },
                ],
                'managedWordLists': [
                    {
                        'match': 'string',
                        'type': 'PROFANITY',
                        'action': 'BLOCKED'
                    },
                ]
            },
            'sensitiveInformationPolicy': {
                'piiEntities': [
                    {
                        'match': 'string',
                        'type': 'ADDRESS'|'AGE'|'AWS_ACCESS_KEY'|'AWS_SECRET_KEY'|'CA_HEALTH_NUMBER'|'CA_SOCIAL_INSURANCE_NUMBER'|'CREDIT_DEBIT_CARD_CVV'|'CREDIT_DEBIT_CARD_EXPIRY'|'CREDIT_DEBIT_CARD_NUMBER'|'DRIVER_ID'|'EMAIL'|'INTERNATIONAL_BANK_ACCOUNT_NUMBER'|'IP_ADDRESS'|'LICENSE_PLATE'|'MAC_ADDRESS'|'NAME'|'PASSWORD'|'PHONE'|'PIN'|'SWIFT_CODE'|'UK_NATIONAL_HEALTH_SERVICE_NUMBER'|'UK_NATIONAL_INSURANCE_NUMBER'|'UK_UNIQUE_TAXPAYER_REFERENCE_NUMBER'|'URL'|'USERNAME'|'US_BANK_ACCOUNT_NUMBER'|'US_BANK_ROUTING_NUMBER'|'US_INDIVIDUAL_TAX_IDENTIFICATION_NUMBER'|'US_PASSPORT_NUMBER'|'US_SOCIAL_SECURITY_NUMBER'|'VEHICLE_IDENTIFICATION_NUMBER',
                        'action': 'ANONYMIZED'|'BLOCKED'
                    },
                ],
                'regexes': [
                    {
                        'name': 'string',
                        'match': 'string',
                        'regex': 'string',
                        'action': 'ANONYMIZED'|'BLOCKED'
                    },
                ]
            },
            'contextualGroundingPolicy': {
                'filters': [
                    {
                        'type': 'GROUNDING'|'RELEVANCE',
                        'threshold': 123.0,
                        'score': 123.0,
                        'action': 'BLOCKED'|'NONE'
                    },
                ]
            }
        },
    ]
}

Response Structure

  • (dict) --

    • usage (dict) --

      The usage details in the response from the guardrail.

      • topicPolicyUnits (integer) --

        The topic policy units processed by the guardrail.

      • contentPolicyUnits (integer) --

        The content policy units processed by the guardrail.

      • wordPolicyUnits (integer) --

        The word policy units processed by the guardrail.

      • sensitiveInformationPolicyUnits (integer) --

        The sensitive information policy units processed by the guardrail.

      • sensitiveInformationPolicyFreeUnits (integer) --

        The sensitive information policy free units processed by the guardrail.

      • contextualGroundingPolicyUnits (integer) --

        The contextual grounding policy units processed by the guardrail.

    • action (string) --

      The action taken in the response from the guardrail.

    • outputs (list) --

      The output details in the response from the guardrail.

      • (dict) --

        The output content produced by the guardrail.

        • text (string) --

          The specific text for the output content produced by the guardrail.

    • assessments (list) --

      The assessment details in the response from the guardrail.

      • (dict) --

        A behavior assessment of the guardrail policies used in a call to the Converse API.

        • topicPolicy (dict) --

          The topic policy.

          • topics (list) --

            The topics in the assessment.

            • (dict) --

              Information about a topic guardrail.

              • name (string) --

                The name for the guardrail.

              • type (string) --

                The type behavior that the guardrail should perform when the model detects the topic.

              • action (string) --

                The action the guardrail should take when it intervenes on a topic.

        • contentPolicy (dict) --

          The content policy.

          • filters (list) --

            The content policy filters.

            • (dict) --

              The content filter for a guardrail.

              • type (string) --

                The guardrail type.

              • confidence (string) --

                The guardrail confidence.

              • action (string) --

                The guardrail action.

        • wordPolicy (dict) --

          The word policy.

          • customWords (list) --

            Custom words in the assessment.

            • (dict) --

              A custom word configured in a guardrail.

              • match (string) --

                The match for the custom word.

              • action (string) --

                The action for the custom word.

          • managedWordLists (list) --

            Managed word lists in the assessment.

            • (dict) --

              A managed word configured in a guardrail.

              • match (string) --

                The match for the managed word.

              • type (string) --

                The type for the managed word.

              • action (string) --

                The action for the managed word.

        • sensitiveInformationPolicy (dict) --

          The sensitive information policy.

          • piiEntities (list) --

            The PII entities in the assessment.

            • (dict) --

              A Personally Identifiable Information (PII) entity configured in a guardrail.

              • match (string) --

                The PII entity filter match.

              • type (string) --

                The PII entity filter type.

              • action (string) --

                The PII entity filter action.

          • regexes (list) --

            The regex queries in the assessment.

            • (dict) --

              A Regex filter configured in a guardrail.

              • name (string) --

                The regex filter name.

              • match (string) --

                The regesx filter match.

              • regex (string) --

                The regex query.

              • action (string) --

                The region filter action.

        • contextualGroundingPolicy (dict) --

          The contextual grounding policy used for the guardrail assessment.

          • filters (list) --

            The filter details for the guardrails contextual grounding filter.

            • (dict) --

              The details for the guardrails contextual grounding filter.

              • type (string) --

                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 (string) --

                The action performed by the guardrails contextual grounding filter.

Converse (updated) Link ¶
Changes (request, response)
Request
{'messages': {'content': {'guardContent': {'text': {'qualifiers': ['grounding_source '
                                                                   '| query | '
                                                                   'guard_content']}}}},
 'system': {'guardContent': {'text': {'qualifiers': ['grounding_source | query '
                                                     '| guard_content']}}}}
Response
{'output': {'message': {'content': {'guardContent': {'text': {'qualifiers': ['grounding_source '
                                                                             '| '
                                                                             'query '
                                                                             '| '
                                                                             'guard_content']}}}}},
 'trace': {'guardrail': {'inputAssessment': {'contextualGroundingPolicy': {'filters': [{'action': 'BLOCKED '
                                                                                                  '| '
                                                                                                  'NONE',
                                                                                        'score': 'double',
                                                                                        'threshold': 'double',
                                                                                        'type': 'GROUNDING '
                                                                                                '| '
                                                                                                'RELEVANCE'}]}},
                         'outputAssessments': {'contextualGroundingPolicy': {'filters': [{'action': 'BLOCKED '
                                                                                                    '| '
                                                                                                    'NONE',
                                                                                          'score': 'double',
                                                                                          'threshold': 'double',
                                                                                          'type': 'GROUNDING '
                                                                                                  '| '
                                                                                                  'RELEVANCE'}]}}}}}

Sends messages to the specified Amazon Bedrock model. Converse provides a consistent interface that works with all models that support messages. This allows you to write code once and use it with different models. Should a model have unique inference parameters, you can also pass those unique parameters to the model.

For information about the Converse API, see Use the Converse API in the Amazon Bedrock User Guide. To use a guardrail, see Use a guardrail with the Converse API in the Amazon Bedrock User Guide. To use a tool with a model, see Tool use (Function calling) in the Amazon Bedrock User Guide

For example code, see Converse API examples in the Amazon Bedrock User Guide.

This operation requires permission for the bedrock:InvokeModel action.

See also: AWS API Documentation

Request Syntax

client.converse(
    modelId='string',
    messages=[
        {
            'role': 'user'|'assistant',
            'content': [
                {
                    'text': 'string',
                    'image': {
                        'format': 'png'|'jpeg'|'gif'|'webp',
                        'source': {
                            'bytes': b'bytes'
                        }
                    },
                    'document': {
                        'format': 'pdf'|'csv'|'doc'|'docx'|'xls'|'xlsx'|'html'|'txt'|'md',
                        'name': 'string',
                        'source': {
                            'bytes': b'bytes'
                        }
                    },
                    'toolUse': {
                        'toolUseId': 'string',
                        'name': 'string',
                        'input': {...}|[...]|123|123.4|'string'|True|None
                    },
                    'toolResult': {
                        'toolUseId': 'string',
                        'content': [
                            {
                                'json': {...}|[...]|123|123.4|'string'|True|None,
                                'text': 'string',
                                'image': {
                                    'format': 'png'|'jpeg'|'gif'|'webp',
                                    'source': {
                                        'bytes': b'bytes'
                                    }
                                },
                                'document': {
                                    'format': 'pdf'|'csv'|'doc'|'docx'|'xls'|'xlsx'|'html'|'txt'|'md',
                                    'name': 'string',
                                    'source': {
                                        'bytes': b'bytes'
                                    }
                                }
                            },
                        ],
                        'status': 'success'|'error'
                    },
                    'guardContent': {
                        'text': {
                            'text': 'string',
                            'qualifiers': [
                                'grounding_source'|'query'|'guard_content',
                            ]
                        }
                    }
                },
            ]
        },
    ],
    system=[
        {
            'text': 'string',
            'guardContent': {
                'text': {
                    'text': 'string',
                    'qualifiers': [
                        'grounding_source'|'query'|'guard_content',
                    ]
                }
            }
        },
    ],
    inferenceConfig={
        'maxTokens': 123,
        'temperature': ...,
        'topP': ...,
        'stopSequences': [
            'string',
        ]
    },
    toolConfig={
        'tools': [
            {
                'toolSpec': {
                    'name': 'string',
                    'description': 'string',
                    'inputSchema': {
                        'json': {...}|[...]|123|123.4|'string'|True|None
                    }
                }
            },
        ],
        'toolChoice': {
            'auto': {}
            ,
            'any': {}
            ,
            'tool': {
                'name': 'string'
            }
        }
    },
    guardrailConfig={
        'guardrailIdentifier': 'string',
        'guardrailVersion': 'string',
        'trace': 'enabled'|'disabled'
    },
    additionalModelRequestFields={...}|[...]|123|123.4|'string'|True|None,
    additionalModelResponseFieldPaths=[
        'string',
    ]
)
type modelId:

string

param modelId:

[REQUIRED]

The identifier for the model that you want to call.

The modelId to provide depends on the type of model that you use:

type messages:

list

param messages:

[REQUIRED]

The messages that you want to send to the model.

  • (dict) --

    A message input, or returned from, a call to Converse or ConverseStream.

    • role (string) -- [REQUIRED]

      The role that the message plays in the message.

    • content (list) -- [REQUIRED]

      The message content. Note the following restrictions:

      • You can include up to 20 images. Each image's size, height, and width must be no more than 3.75 MB, 8000 px, and 8000 px, respectively.

      • You can include up to five documents. Each document's size must be no more than 4.5 MB.

      • If you include a ContentBlock with a document field in the array, you must also include a ContentBlock with a text field.

      • You can only include images and documents if the role is user.

      • (dict) --

        A block of content for a message that you pass to, or receive from, a model with the Converse or ConverseStream API operations.

        • text (string) --

          Text to include in the message.

        • image (dict) --

          Image to include in the message.

          • format (string) -- [REQUIRED]

            The format of the image.

          • source (dict) -- [REQUIRED]

            The source for the image.

            • bytes (bytes) --

              The raw image bytes for the image. If you use an AWS SDK, you don't need to encode the image bytes in base64.

        • document (dict) --

          A document to include in the message.

          • format (string) -- [REQUIRED]

            The format of a document, or its extension.

          • name (string) -- [REQUIRED]

            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

          • source (dict) -- [REQUIRED]

            Contains the content of the document.

            • bytes (bytes) --

              The raw bytes for the document. If you use an Amazon Web Services SDK, you don't need to encode the bytes in base64.

        • toolUse (dict) --

          Information about a tool use request from a model.

          • toolUseId (string) -- [REQUIRED]

            The ID for the tool request.

          • name (string) -- [REQUIRED]

            The name of the tool that the model wants to use.

          • input (:ref:`document<document>`) -- [REQUIRED]

            The input to pass to the tool.

        • toolResult (dict) --

          The result for a tool request that a model makes.

          • toolUseId (string) -- [REQUIRED]

            The ID of the tool request that this is the result for.

          • content (list) -- [REQUIRED]

            The content for tool result content block.

            • (dict) --

              The tool result content block.

              • json (:ref:`document<document>`) --

                A tool result that is JSON format data.

              • text (string) --

                A tool result that is text.

              • image (dict) --

                A tool result that is an image.

                • format (string) -- [REQUIRED]

                  The format of the image.

                • source (dict) -- [REQUIRED]

                  The source for the image.

                  • bytes (bytes) --

                    The raw image bytes for the image. If you use an AWS SDK, you don't need to encode the image bytes in base64.

              • document (dict) --

                A tool result that is a document.

                • format (string) -- [REQUIRED]

                  The format of a document, or its extension.

                • name (string) -- [REQUIRED]

                  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

                • source (dict) -- [REQUIRED]

                  Contains the content of the document.

                  • bytes (bytes) --

                    The raw bytes for the document. If you use an Amazon Web Services SDK, you don't need to encode the bytes in base64.

          • status (string) --

            The status for the tool result content block.

        • guardContent (dict) --

          Contains the content to assess with the guardrail. If you don't specify guardContent in a call to the Converse API, the guardrail (if passed in the Converse API) assesses the entire message.

          For more information, see Use a guardrail with the Converse API in the Amazon Bedrock User Guide. </p>

          • text (dict) --

            The text to guard.

            • text (string) -- [REQUIRED]

              The text that you want to guard.

            • qualifiers (list) --

              The qualifier details for the guardrails contextual grounding filter.

              • (string) --

type system:

list

param system:

A system prompt to pass to the model.

  • (dict) --

    A system content block.

    • text (string) --

      A system prompt for the model.

    • guardContent (dict) --

      A content block to assess with the guardrail. Use with the Converse or ConverseStream API operations.

      For more information, see Use a guardrail with the Converse API in the Amazon Bedrock User Guide.

      • text (dict) --

        The text to guard.

        • text (string) -- [REQUIRED]

          The text that you want to guard.

        • qualifiers (list) --

          The qualifier details for the guardrails contextual grounding filter.

          • (string) --

type inferenceConfig:

dict

param inferenceConfig:

Inference parameters to pass to the model. Converse supports a base set of inference parameters. If you need to pass additional parameters that the model supports, use the additionalModelRequestFields request field.

  • maxTokens (integer) --

    The maximum number of tokens to allow in the generated response. The default value is the maximum allowed value for the model that you are using. For more information, see Inference parameters for foundation models.

  • temperature (float) --

    The likelihood of the model selecting higher-probability options while generating a response. A lower value makes the model more likely to choose higher-probability options, while a higher value makes the model more likely to choose lower-probability options.

    The default value is the default value for the model that you are using. For more information, see Inference parameters for foundation models.

  • topP (float) --

    The percentage of most-likely candidates that the model considers for the next token. For example, if you choose a value of 0.8 for topP, the model selects from the top 80% of the probability distribution of tokens that could be next in the sequence.

    The default value is the default value for the model that you are using. For more information, see Inference parameters for foundation models.

  • stopSequences (list) --

    A list of stop sequences. A stop sequence is a sequence of characters that causes the model to stop generating the response.

    • (string) --

type toolConfig:

dict

param toolConfig:

Configuration information for the tools that the model can use when generating a response.

  • tools (list) -- [REQUIRED]

    An array of tools that you want to pass to a model.

    • (dict) --

      Information about a tool that you can use with the Converse API. For more information, see Tool use (function calling) in the Amazon Bedrock User Guide.

      • toolSpec (dict) --

        The specfication for the tool.

        • name (string) -- [REQUIRED]

          The name for the tool.

        • description (string) --

          The description for the tool.

        • inputSchema (dict) -- [REQUIRED]

          The input schema for the tool in JSON format.

          • json (:ref:`document<document>`) --

            The JSON schema for the tool. For more information, see JSON Schema Reference.

  • toolChoice (dict) --

    If supported by model, forces the model to request a tool.

    • auto (dict) --

      (Default). The Model automatically decides if a tool should be called or whether to generate text instead.

    • any (dict) --

      The model must request at least one tool (no text is generated).

    • tool (dict) --

      The Model must request the specified tool. Only supported by Anthropic Claude 3 models.

      • name (string) -- [REQUIRED]

        The name of the tool that the model must request.

type guardrailConfig:

dict

param guardrailConfig:

Configuration information for a guardrail that you want to use in the request.

  • guardrailIdentifier (string) -- [REQUIRED]

    The identifier for the guardrail.

  • guardrailVersion (string) -- [REQUIRED]

    The version of the guardrail.

  • trace (string) --

    The trace behavior for the guardrail.

type additionalModelRequestFields:

:ref:`document<document>`

param additionalModelRequestFields:

Additional inference parameters that the model supports, beyond the base set of inference parameters that Converse supports in the inferenceConfig field. For more information, see Model parameters.

type additionalModelResponseFieldPaths:

list

param additionalModelResponseFieldPaths:

Additional model parameters field paths to return in the response. Converse returns the requested fields as a JSON Pointer object in the additionalModelResponseFields field. The following is example JSON for additionalModelResponseFieldPaths.

[ "/stop_sequence" ]

For information about the JSON Pointer syntax, see the Internet Engineering Task Force (IETF) documentation.

Converse rejects an empty JSON Pointer or incorrectly structured JSON Pointer with a 400 error code. if the JSON Pointer is valid, but the requested field is not in the model response, it is ignored by Converse.

  • (string) --

rtype:

dict

returns:

Response Syntax

{
    'output': {
        'message': {
            'role': 'user'|'assistant',
            'content': [
                {
                    'text': 'string',
                    'image': {
                        'format': 'png'|'jpeg'|'gif'|'webp',
                        'source': {
                            'bytes': b'bytes'
                        }
                    },
                    'document': {
                        'format': 'pdf'|'csv'|'doc'|'docx'|'xls'|'xlsx'|'html'|'txt'|'md',
                        'name': 'string',
                        'source': {
                            'bytes': b'bytes'
                        }
                    },
                    'toolUse': {
                        'toolUseId': 'string',
                        'name': 'string',
                        'input': {...}|[...]|123|123.4|'string'|True|None
                    },
                    'toolResult': {
                        'toolUseId': 'string',
                        'content': [
                            {
                                'json': {...}|[...]|123|123.4|'string'|True|None,
                                'text': 'string',
                                'image': {
                                    'format': 'png'|'jpeg'|'gif'|'webp',
                                    'source': {
                                        'bytes': b'bytes'
                                    }
                                },
                                'document': {
                                    'format': 'pdf'|'csv'|'doc'|'docx'|'xls'|'xlsx'|'html'|'txt'|'md',
                                    'name': 'string',
                                    'source': {
                                        'bytes': b'bytes'
                                    }
                                }
                            },
                        ],
                        'status': 'success'|'error'
                    },
                    'guardContent': {
                        'text': {
                            'text': 'string',
                            'qualifiers': [
                                'grounding_source'|'query'|'guard_content',
                            ]
                        }
                    }
                },
            ]
        }
    },
    'stopReason': 'end_turn'|'tool_use'|'max_tokens'|'stop_sequence'|'guardrail_intervened'|'content_filtered',
    'usage': {
        'inputTokens': 123,
        'outputTokens': 123,
        'totalTokens': 123
    },
    'metrics': {
        'latencyMs': 123
    },
    'additionalModelResponseFields': {...}|[...]|123|123.4|'string'|True|None,
    'trace': {
        'guardrail': {
            'modelOutput': [
                'string',
            ],
            'inputAssessment': {
                'string': {
                    'topicPolicy': {
                        'topics': [
                            {
                                'name': 'string',
                                'type': 'DENY',
                                'action': 'BLOCKED'
                            },
                        ]
                    },
                    'contentPolicy': {
                        'filters': [
                            {
                                'type': 'INSULTS'|'HATE'|'SEXUAL'|'VIOLENCE'|'MISCONDUCT'|'PROMPT_ATTACK',
                                'confidence': 'NONE'|'LOW'|'MEDIUM'|'HIGH',
                                'action': 'BLOCKED'
                            },
                        ]
                    },
                    'wordPolicy': {
                        'customWords': [
                            {
                                'match': 'string',
                                'action': 'BLOCKED'
                            },
                        ],
                        'managedWordLists': [
                            {
                                'match': 'string',
                                'type': 'PROFANITY',
                                'action': 'BLOCKED'
                            },
                        ]
                    },
                    'sensitiveInformationPolicy': {
                        'piiEntities': [
                            {
                                'match': 'string',
                                'type': 'ADDRESS'|'AGE'|'AWS_ACCESS_KEY'|'AWS_SECRET_KEY'|'CA_HEALTH_NUMBER'|'CA_SOCIAL_INSURANCE_NUMBER'|'CREDIT_DEBIT_CARD_CVV'|'CREDIT_DEBIT_CARD_EXPIRY'|'CREDIT_DEBIT_CARD_NUMBER'|'DRIVER_ID'|'EMAIL'|'INTERNATIONAL_BANK_ACCOUNT_NUMBER'|'IP_ADDRESS'|'LICENSE_PLATE'|'MAC_ADDRESS'|'NAME'|'PASSWORD'|'PHONE'|'PIN'|'SWIFT_CODE'|'UK_NATIONAL_HEALTH_SERVICE_NUMBER'|'UK_NATIONAL_INSURANCE_NUMBER'|'UK_UNIQUE_TAXPAYER_REFERENCE_NUMBER'|'URL'|'USERNAME'|'US_BANK_ACCOUNT_NUMBER'|'US_BANK_ROUTING_NUMBER'|'US_INDIVIDUAL_TAX_IDENTIFICATION_NUMBER'|'US_PASSPORT_NUMBER'|'US_SOCIAL_SECURITY_NUMBER'|'VEHICLE_IDENTIFICATION_NUMBER',
                                'action': 'ANONYMIZED'|'BLOCKED'
                            },
                        ],
                        'regexes': [
                            {
                                'name': 'string',
                                'match': 'string',
                                'regex': 'string',
                                'action': 'ANONYMIZED'|'BLOCKED'
                            },
                        ]
                    },
                    'contextualGroundingPolicy': {
                        'filters': [
                            {
                                'type': 'GROUNDING'|'RELEVANCE',
                                'threshold': 123.0,
                                'score': 123.0,
                                'action': 'BLOCKED'|'NONE'
                            },
                        ]
                    }
                }
            },
            'outputAssessments': {
                'string': [
                    {
                        'topicPolicy': {
                            'topics': [
                                {
                                    'name': 'string',
                                    'type': 'DENY',
                                    'action': 'BLOCKED'
                                },
                            ]
                        },
                        'contentPolicy': {
                            'filters': [
                                {
                                    'type': 'INSULTS'|'HATE'|'SEXUAL'|'VIOLENCE'|'MISCONDUCT'|'PROMPT_ATTACK',
                                    'confidence': 'NONE'|'LOW'|'MEDIUM'|'HIGH',
                                    'action': 'BLOCKED'
                                },
                            ]
                        },
                        'wordPolicy': {
                            'customWords': [
                                {
                                    'match': 'string',
                                    'action': 'BLOCKED'
                                },
                            ],
                            'managedWordLists': [
                                {
                                    'match': 'string',
                                    'type': 'PROFANITY',
                                    'action': 'BLOCKED'
                                },
                            ]
                        },
                        'sensitiveInformationPolicy': {
                            'piiEntities': [
                                {
                                    'match': 'string',
                                    'type': 'ADDRESS'|'AGE'|'AWS_ACCESS_KEY'|'AWS_SECRET_KEY'|'CA_HEALTH_NUMBER'|'CA_SOCIAL_INSURANCE_NUMBER'|'CREDIT_DEBIT_CARD_CVV'|'CREDIT_DEBIT_CARD_EXPIRY'|'CREDIT_DEBIT_CARD_NUMBER'|'DRIVER_ID'|'EMAIL'|'INTERNATIONAL_BANK_ACCOUNT_NUMBER'|'IP_ADDRESS'|'LICENSE_PLATE'|'MAC_ADDRESS'|'NAME'|'PASSWORD'|'PHONE'|'PIN'|'SWIFT_CODE'|'UK_NATIONAL_HEALTH_SERVICE_NUMBER'|'UK_NATIONAL_INSURANCE_NUMBER'|'UK_UNIQUE_TAXPAYER_REFERENCE_NUMBER'|'URL'|'USERNAME'|'US_BANK_ACCOUNT_NUMBER'|'US_BANK_ROUTING_NUMBER'|'US_INDIVIDUAL_TAX_IDENTIFICATION_NUMBER'|'US_PASSPORT_NUMBER'|'US_SOCIAL_SECURITY_NUMBER'|'VEHICLE_IDENTIFICATION_NUMBER',
                                    'action': 'ANONYMIZED'|'BLOCKED'
                                },
                            ],
                            'regexes': [
                                {
                                    'name': 'string',
                                    'match': 'string',
                                    'regex': 'string',
                                    'action': 'ANONYMIZED'|'BLOCKED'
                                },
                            ]
                        },
                        'contextualGroundingPolicy': {
                            'filters': [
                                {
                                    'type': 'GROUNDING'|'RELEVANCE',
                                    'threshold': 123.0,
                                    'score': 123.0,
                                    'action': 'BLOCKED'|'NONE'
                                },
                            ]
                        }
                    },
                ]
            }
        }
    }
}

Response Structure

  • (dict) --

    • output (dict) --

      The result from the call to Converse.

      • message (dict) --

        The message that the model generates.

        • role (string) --

          The role that the message plays in the message.

        • content (list) --

          The message content. Note the following restrictions:

          • You can include up to 20 images. Each image's size, height, and width must be no more than 3.75 MB, 8000 px, and 8000 px, respectively.

          • You can include up to five documents. Each document's size must be no more than 4.5 MB.

          • If you include a ContentBlock with a document field in the array, you must also include a ContentBlock with a text field.

          • You can only include images and documents if the role is user.

          • (dict) --

            A block of content for a message that you pass to, or receive from, a model with the Converse or ConverseStream API operations.

            • text (string) --

              Text to include in the message.

            • image (dict) --

              Image to include in the message.

              • format (string) --

                The format of the image.

              • source (dict) --

                The source for the image.

                • bytes (bytes) --

                  The raw image bytes for the image. If you use an AWS SDK, you don't need to encode the image bytes in base64.

            • document (dict) --

              A document to include in the message.

              • format (string) --

                The format of a document, or its extension.

              • name (string) --

                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

              • source (dict) --

                Contains the content of the document.

                • bytes (bytes) --

                  The raw bytes for the document. If you use an Amazon Web Services SDK, you don't need to encode the bytes in base64.

            • toolUse (dict) --

              Information about a tool use request from a model.

              • toolUseId (string) --

                The ID for the tool request.

              • name (string) --

                The name of the tool that the model wants to use.

              • input (:ref:`document<document>`) --

                The input to pass to the tool.

            • toolResult (dict) --

              The result for a tool request that a model makes.

              • toolUseId (string) --

                The ID of the tool request that this is the result for.

              • content (list) --

                The content for tool result content block.

                • (dict) --

                  The tool result content block.

                  • json (:ref:`document<document>`) --

                    A tool result that is JSON format data.

                  • text (string) --

                    A tool result that is text.

                  • image (dict) --

                    A tool result that is an image.

                    • format (string) --

                      The format of the image.

                    • source (dict) --

                      The source for the image.

                      • bytes (bytes) --

                        The raw image bytes for the image. If you use an AWS SDK, you don't need to encode the image bytes in base64.

                  • document (dict) --

                    A tool result that is a document.

                    • format (string) --

                      The format of a document, or its extension.

                    • name (string) --

                      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

                    • source (dict) --

                      Contains the content of the document.

                      • bytes (bytes) --

                        The raw bytes for the document. If you use an Amazon Web Services SDK, you don't need to encode the bytes in base64.

              • status (string) --

                The status for the tool result content block.

            • guardContent (dict) --

              Contains the content to assess with the guardrail. If you don't specify guardContent in a call to the Converse API, the guardrail (if passed in the Converse API) assesses the entire message.

              For more information, see Use a guardrail with the Converse API in the Amazon Bedrock User Guide. </p>

              • text (dict) --

                The text to guard.

                • text (string) --

                  The text that you want to guard.

                • qualifiers (list) --

                  The qualifier details for the guardrails contextual grounding filter.

                  • (string) --

    • stopReason (string) --

      The reason why the model stopped generating output.

    • usage (dict) --

      The total number of tokens used in the call to Converse. The total includes the tokens input to the model and the tokens generated by the model.

      • inputTokens (integer) --

        The number of tokens sent in the request to the model.

      • outputTokens (integer) --

        The number of tokens that the model generated for the request.

      • totalTokens (integer) --

        The total of input tokens and tokens generated by the model.

    • metrics (dict) --

      Metrics for the call to Converse.

      • latencyMs (integer) --

        The latency of the call to Converse, in milliseconds.

    • additionalModelResponseFields (:ref:`document<document>`) --

      Additional fields in the response that are unique to the model.

    • trace (dict) --

      A trace object that contains information about the Guardrail behavior.

      • guardrail (dict) --

        The guardrail trace object.

        • modelOutput (list) --

          The output from the model.

          • (string) --

        • inputAssessment (dict) --

          The input assessment.

          • (string) --

            • (dict) --

              A behavior assessment of the guardrail policies used in a call to the Converse API.

              • topicPolicy (dict) --

                The topic policy.

                • topics (list) --

                  The topics in the assessment.

                  • (dict) --

                    Information about a topic guardrail.

                    • name (string) --

                      The name for the guardrail.

                    • type (string) --

                      The type behavior that the guardrail should perform when the model detects the topic.

                    • action (string) --

                      The action the guardrail should take when it intervenes on a topic.

              • contentPolicy (dict) --

                The content policy.

                • filters (list) --

                  The content policy filters.

                  • (dict) --

                    The content filter for a guardrail.

                    • type (string) --

                      The guardrail type.

                    • confidence (string) --

                      The guardrail confidence.

                    • action (string) --

                      The guardrail action.

              • wordPolicy (dict) --

                The word policy.

                • customWords (list) --

                  Custom words in the assessment.

                  • (dict) --

                    A custom word configured in a guardrail.

                    • match (string) --

                      The match for the custom word.

                    • action (string) --

                      The action for the custom word.

                • managedWordLists (list) --

                  Managed word lists in the assessment.

                  • (dict) --

                    A managed word configured in a guardrail.

                    • match (string) --

                      The match for the managed word.

                    • type (string) --

                      The type for the managed word.

                    • action (string) --

                      The action for the managed word.

              • sensitiveInformationPolicy (dict) --

                The sensitive information policy.

                • piiEntities (list) --

                  The PII entities in the assessment.

                  • (dict) --

                    A Personally Identifiable Information (PII) entity configured in a guardrail.

                    • match (string) --

                      The PII entity filter match.

                    • type (string) --

                      The PII entity filter type.

                    • action (string) --

                      The PII entity filter action.

                • regexes (list) --

                  The regex queries in the assessment.

                  • (dict) --

                    A Regex filter configured in a guardrail.

                    • name (string) --

                      The regex filter name.

                    • match (string) --

                      The regesx filter match.

                    • regex (string) --

                      The regex query.

                    • action (string) --

                      The region filter action.

              • contextualGroundingPolicy (dict) --

                The contextual grounding policy used for the guardrail assessment.

                • filters (list) --

                  The filter details for the guardrails contextual grounding filter.

                  • (dict) --

                    The details for the guardrails contextual grounding filter.

                    • type (string) --

                      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 (string) --

                      The action performed by the guardrails contextual grounding filter.

        • outputAssessments (dict) --

          the output assessments.

          • (string) --

            • (list) --

              • (dict) --

                A behavior assessment of the guardrail policies used in a call to the Converse API.

                • topicPolicy (dict) --

                  The topic policy.

                  • topics (list) --

                    The topics in the assessment.

                    • (dict) --

                      Information about a topic guardrail.

                      • name (string) --

                        The name for the guardrail.

                      • type (string) --

                        The type behavior that the guardrail should perform when the model detects the topic.

                      • action (string) --

                        The action the guardrail should take when it intervenes on a topic.

                • contentPolicy (dict) --

                  The content policy.

                  • filters (list) --

                    The content policy filters.

                    • (dict) --

                      The content filter for a guardrail.

                      • type (string) --

                        The guardrail type.

                      • confidence (string) --

                        The guardrail confidence.

                      • action (string) --

                        The guardrail action.

                • wordPolicy (dict) --

                  The word policy.

                  • customWords (list) --

                    Custom words in the assessment.

                    • (dict) --

                      A custom word configured in a guardrail.

                      • match (string) --

                        The match for the custom word.

                      • action (string) --

                        The action for the custom word.

                  • managedWordLists (list) --

                    Managed word lists in the assessment.

                    • (dict) --

                      A managed word configured in a guardrail.

                      • match (string) --

                        The match for the managed word.

                      • type (string) --

                        The type for the managed word.

                      • action (string) --

                        The action for the managed word.

                • sensitiveInformationPolicy (dict) --

                  The sensitive information policy.

                  • piiEntities (list) --

                    The PII entities in the assessment.

                    • (dict) --

                      A Personally Identifiable Information (PII) entity configured in a guardrail.

                      • match (string) --

                        The PII entity filter match.

                      • type (string) --

                        The PII entity filter type.

                      • action (string) --

                        The PII entity filter action.

                  • regexes (list) --

                    The regex queries in the assessment.

                    • (dict) --

                      A Regex filter configured in a guardrail.

                      • name (string) --

                        The regex filter name.

                      • match (string) --

                        The regesx filter match.

                      • regex (string) --

                        The regex query.

                      • action (string) --

                        The region filter action.

                • contextualGroundingPolicy (dict) --

                  The contextual grounding policy used for the guardrail assessment.

                  • filters (list) --

                    The filter details for the guardrails contextual grounding filter.

                    • (dict) --

                      The details for the guardrails contextual grounding filter.

                      • type (string) --

                        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 (string) --

                        The action performed by the guardrails contextual grounding filter.

ConverseStream (updated) Link ¶
Changes (request, response)
Request
{'messages': {'content': {'guardContent': {'text': {'qualifiers': ['grounding_source '
                                                                   '| query | '
                                                                   'guard_content']}}}},
 'system': {'guardContent': {'text': {'qualifiers': ['grounding_source | query '
                                                     '| guard_content']}}}}
Response
{'stream': {'metadata': {'trace': {'guardrail': {'inputAssessment': {'contextualGroundingPolicy': {'filters': [{'action': 'BLOCKED '
                                                                                                                          '| '
                                                                                                                          'NONE',
                                                                                                                'score': 'double',
                                                                                                                'threshold': 'double',
                                                                                                                'type': 'GROUNDING '
                                                                                                                        '| '
                                                                                                                        'RELEVANCE'}]}},
                                                 'outputAssessments': {'contextualGroundingPolicy': {'filters': [{'action': 'BLOCKED '
                                                                                                                            '| '
                                                                                                                            'NONE',
                                                                                                                  'score': 'double',
                                                                                                                  'threshold': 'double',
                                                                                                                  'type': 'GROUNDING '
                                                                                                                          '| '
                                                                                                                          'RELEVANCE'}]}}}}}}}

Sends messages to the specified Amazon Bedrock model and returns the response in a stream. ConverseStream provides a consistent API that works with all Amazon Bedrock models that support messages. This allows you to write code once and use it with different models. Should a model have unique inference parameters, you can also pass those unique parameters to the model.

To find out if a model supports streaming, call GetFoundationModel and check the responseStreamingSupported field in the response.

For information about the Converse API, see Use the Converse API in the Amazon Bedrock User Guide. To use a guardrail, see Use a guardrail with the Converse API in the Amazon Bedrock User Guide. To use a tool with a model, see Tool use (Function calling) in the Amazon Bedrock User Guide

For example code, see Conversation streaming example in the Amazon Bedrock User Guide.

This operation requires permission for the bedrock:InvokeModelWithResponseStream action.

See also: AWS API Documentation

Request Syntax

client.converse_stream(
    modelId='string',
    messages=[
        {
            'role': 'user'|'assistant',
            'content': [
                {
                    'text': 'string',
                    'image': {
                        'format': 'png'|'jpeg'|'gif'|'webp',
                        'source': {
                            'bytes': b'bytes'
                        }
                    },
                    'document': {
                        'format': 'pdf'|'csv'|'doc'|'docx'|'xls'|'xlsx'|'html'|'txt'|'md',
                        'name': 'string',
                        'source': {
                            'bytes': b'bytes'
                        }
                    },
                    'toolUse': {
                        'toolUseId': 'string',
                        'name': 'string',
                        'input': {...}|[...]|123|123.4|'string'|True|None
                    },
                    'toolResult': {
                        'toolUseId': 'string',
                        'content': [
                            {
                                'json': {...}|[...]|123|123.4|'string'|True|None,
                                'text': 'string',
                                'image': {
                                    'format': 'png'|'jpeg'|'gif'|'webp',
                                    'source': {
                                        'bytes': b'bytes'
                                    }
                                },
                                'document': {
                                    'format': 'pdf'|'csv'|'doc'|'docx'|'xls'|'xlsx'|'html'|'txt'|'md',
                                    'name': 'string',
                                    'source': {
                                        'bytes': b'bytes'
                                    }
                                }
                            },
                        ],
                        'status': 'success'|'error'
                    },
                    'guardContent': {
                        'text': {
                            'text': 'string',
                            'qualifiers': [
                                'grounding_source'|'query'|'guard_content',
                            ]
                        }
                    }
                },
            ]
        },
    ],
    system=[
        {
            'text': 'string',
            'guardContent': {
                'text': {
                    'text': 'string',
                    'qualifiers': [
                        'grounding_source'|'query'|'guard_content',
                    ]
                }
            }
        },
    ],
    inferenceConfig={
        'maxTokens': 123,
        'temperature': ...,
        'topP': ...,
        'stopSequences': [
            'string',
        ]
    },
    toolConfig={
        'tools': [
            {
                'toolSpec': {
                    'name': 'string',
                    'description': 'string',
                    'inputSchema': {
                        'json': {...}|[...]|123|123.4|'string'|True|None
                    }
                }
            },
        ],
        'toolChoice': {
            'auto': {}
            ,
            'any': {}
            ,
            'tool': {
                'name': 'string'
            }
        }
    },
    guardrailConfig={
        'guardrailIdentifier': 'string',
        'guardrailVersion': 'string',
        'trace': 'enabled'|'disabled',
        'streamProcessingMode': 'sync'|'async'
    },
    additionalModelRequestFields={...}|[...]|123|123.4|'string'|True|None,
    additionalModelResponseFieldPaths=[
        'string',
    ]
)
type modelId:

string

param modelId:

[REQUIRED]

The ID for the model.

The modelId to provide depends on the type of model that you use:

type messages:

list

param messages:

[REQUIRED]

The messages that you want to send to the model.

  • (dict) --

    A message input, or returned from, a call to Converse or ConverseStream.

    • role (string) -- [REQUIRED]

      The role that the message plays in the message.

    • content (list) -- [REQUIRED]

      The message content. Note the following restrictions:

      • You can include up to 20 images. Each image's size, height, and width must be no more than 3.75 MB, 8000 px, and 8000 px, respectively.

      • You can include up to five documents. Each document's size must be no more than 4.5 MB.

      • If you include a ContentBlock with a document field in the array, you must also include a ContentBlock with a text field.

      • You can only include images and documents if the role is user.

      • (dict) --

        A block of content for a message that you pass to, or receive from, a model with the Converse or ConverseStream API operations.

        • text (string) --

          Text to include in the message.

        • image (dict) --

          Image to include in the message.

          • format (string) -- [REQUIRED]

            The format of the image.

          • source (dict) -- [REQUIRED]

            The source for the image.

            • bytes (bytes) --

              The raw image bytes for the image. If you use an AWS SDK, you don't need to encode the image bytes in base64.

        • document (dict) --

          A document to include in the message.

          • format (string) -- [REQUIRED]

            The format of a document, or its extension.

          • name (string) -- [REQUIRED]

            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

          • source (dict) -- [REQUIRED]

            Contains the content of the document.

            • bytes (bytes) --

              The raw bytes for the document. If you use an Amazon Web Services SDK, you don't need to encode the bytes in base64.

        • toolUse (dict) --

          Information about a tool use request from a model.

          • toolUseId (string) -- [REQUIRED]

            The ID for the tool request.

          • name (string) -- [REQUIRED]

            The name of the tool that the model wants to use.

          • input (:ref:`document<document>`) -- [REQUIRED]

            The input to pass to the tool.

        • toolResult (dict) --

          The result for a tool request that a model makes.

          • toolUseId (string) -- [REQUIRED]

            The ID of the tool request that this is the result for.

          • content (list) -- [REQUIRED]

            The content for tool result content block.

            • (dict) --

              The tool result content block.

              • json (:ref:`document<document>`) --

                A tool result that is JSON format data.

              • text (string) --

                A tool result that is text.

              • image (dict) --

                A tool result that is an image.

                • format (string) -- [REQUIRED]

                  The format of the image.

                • source (dict) -- [REQUIRED]

                  The source for the image.

                  • bytes (bytes) --

                    The raw image bytes for the image. If you use an AWS SDK, you don't need to encode the image bytes in base64.

              • document (dict) --

                A tool result that is a document.

                • format (string) -- [REQUIRED]

                  The format of a document, or its extension.

                • name (string) -- [REQUIRED]

                  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

                • source (dict) -- [REQUIRED]

                  Contains the content of the document.

                  • bytes (bytes) --

                    The raw bytes for the document. If you use an Amazon Web Services SDK, you don't need to encode the bytes in base64.

          • status (string) --

            The status for the tool result content block.

        • guardContent (dict) --

          Contains the content to assess with the guardrail. If you don't specify guardContent in a call to the Converse API, the guardrail (if passed in the Converse API) assesses the entire message.

          For more information, see Use a guardrail with the Converse API in the Amazon Bedrock User Guide. </p>

          • text (dict) --

            The text to guard.

            • text (string) -- [REQUIRED]

              The text that you want to guard.

            • qualifiers (list) --

              The qualifier details for the guardrails contextual grounding filter.

              • (string) --

type system:

list

param system:

A system prompt to send to the model.

  • (dict) --

    A system content block.

    • text (string) --

      A system prompt for the model.

    • guardContent (dict) --

      A content block to assess with the guardrail. Use with the Converse or ConverseStream API operations.

      For more information, see Use a guardrail with the Converse API in the Amazon Bedrock User Guide.

      • text (dict) --

        The text to guard.

        • text (string) -- [REQUIRED]

          The text that you want to guard.

        • qualifiers (list) --

          The qualifier details for the guardrails contextual grounding filter.

          • (string) --

type inferenceConfig:

dict

param inferenceConfig:

Inference parameters to pass to the model. ConverseStream supports a base set of inference parameters. If you need to pass additional parameters that the model supports, use the additionalModelRequestFields request field.

  • maxTokens (integer) --

    The maximum number of tokens to allow in the generated response. The default value is the maximum allowed value for the model that you are using. For more information, see Inference parameters for foundation models.

  • temperature (float) --

    The likelihood of the model selecting higher-probability options while generating a response. A lower value makes the model more likely to choose higher-probability options, while a higher value makes the model more likely to choose lower-probability options.

    The default value is the default value for the model that you are using. For more information, see Inference parameters for foundation models.

  • topP (float) --

    The percentage of most-likely candidates that the model considers for the next token. For example, if you choose a value of 0.8 for topP, the model selects from the top 80% of the probability distribution of tokens that could be next in the sequence.

    The default value is the default value for the model that you are using. For more information, see Inference parameters for foundation models.

  • stopSequences (list) --

    A list of stop sequences. A stop sequence is a sequence of characters that causes the model to stop generating the response.

    • (string) --

type toolConfig:

dict

param toolConfig:

Configuration information for the tools that the model can use when generating a response.

  • tools (list) -- [REQUIRED]

    An array of tools that you want to pass to a model.

    • (dict) --

      Information about a tool that you can use with the Converse API. For more information, see Tool use (function calling) in the Amazon Bedrock User Guide.

      • toolSpec (dict) --

        The specfication for the tool.

        • name (string) -- [REQUIRED]

          The name for the tool.

        • description (string) --

          The description for the tool.

        • inputSchema (dict) -- [REQUIRED]

          The input schema for the tool in JSON format.

          • json (:ref:`document<document>`) --

            The JSON schema for the tool. For more information, see JSON Schema Reference.

  • toolChoice (dict) --

    If supported by model, forces the model to request a tool.

    • auto (:class:`.EventStream`) --

      (Default). The Model automatically decides if a tool should be called or whether to generate text instead.

    • any (:class:`.EventStream`) --

      The model must request at least one tool (no text is generated).

    • tool (dict) --

      The Model must request the specified tool. Only supported by Anthropic Claude 3 models.

      • name (string) -- [REQUIRED]

        The name of the tool that the model must request.

type guardrailConfig:

dict

param guardrailConfig:

Configuration information for a guardrail that you want to use in the request.

  • guardrailIdentifier (string) -- [REQUIRED]

    The identifier for the guardrail.

  • guardrailVersion (string) -- [REQUIRED]

    The version of the guardrail.

  • trace (string) --

    The trace behavior for the guardrail.

  • streamProcessingMode (string) --

    The processing mode.

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

type additionalModelRequestFields:

:ref:`document<document>`

param additionalModelRequestFields:

Additional inference parameters that the model supports, beyond the base set of inference parameters that ConverseStream supports in the inferenceConfig field.

type additionalModelResponseFieldPaths:

list

param additionalModelResponseFieldPaths:

Additional model parameters field paths to return in the response. ConverseStream returns the requested fields as a JSON Pointer object in the additionalModelResponseFields field. The following is example JSON for additionalModelResponseFieldPaths.

[ "/stop_sequence" ]

For information about the JSON Pointer syntax, see the Internet Engineering Task Force (IETF) documentation.

ConverseStream rejects an empty JSON Pointer or incorrectly structured JSON Pointer with a 400 error code. if the JSON Pointer is valid, but the requested field is not in the model response, it is ignored by ConverseStream.

  • (string) --

rtype:

dict

returns:

The response of this operation contains an :class:`.EventStream` member. When iterated the :class:`.EventStream` will yield events based on the structure below, where only one of the top level keys will be present for any given event.

Response Syntax

{
    'stream': EventStream({
        'messageStart': {
            'role': 'user'|'assistant'
        },
        'contentBlockStart': {
            'start': {
                'toolUse': {
                    'toolUseId': 'string',
                    'name': 'string'
                }
            },
            'contentBlockIndex': 123
        },
        'contentBlockDelta': {
            'delta': {
                'text': 'string',
                'toolUse': {
                    'input': 'string'
                }
            },
            'contentBlockIndex': 123
        },
        'contentBlockStop': {
            'contentBlockIndex': 123
        },
        'messageStop': {
            'stopReason': 'end_turn'|'tool_use'|'max_tokens'|'stop_sequence'|'guardrail_intervened'|'content_filtered',
            'additionalModelResponseFields': {...}|[...]|123|123.4|'string'|True|None
        },
        'metadata': {
            'usage': {
                'inputTokens': 123,
                'outputTokens': 123,
                'totalTokens': 123
            },
            'metrics': {
                'latencyMs': 123
            },
            'trace': {
                'guardrail': {
                    'modelOutput': [
                        'string',
                    ],
                    'inputAssessment': {
                        'string': {
                            'topicPolicy': {
                                'topics': [
                                    {
                                        'name': 'string',
                                        'type': 'DENY',
                                        'action': 'BLOCKED'
                                    },
                                ]
                            },
                            'contentPolicy': {
                                'filters': [
                                    {
                                        'type': 'INSULTS'|'HATE'|'SEXUAL'|'VIOLENCE'|'MISCONDUCT'|'PROMPT_ATTACK',
                                        'confidence': 'NONE'|'LOW'|'MEDIUM'|'HIGH',
                                        'action': 'BLOCKED'
                                    },
                                ]
                            },
                            'wordPolicy': {
                                'customWords': [
                                    {
                                        'match': 'string',
                                        'action': 'BLOCKED'
                                    },
                                ],
                                'managedWordLists': [
                                    {
                                        'match': 'string',
                                        'type': 'PROFANITY',
                                        'action': 'BLOCKED'
                                    },
                                ]
                            },
                            'sensitiveInformationPolicy': {
                                'piiEntities': [
                                    {
                                        'match': 'string',
                                        'type': 'ADDRESS'|'AGE'|'AWS_ACCESS_KEY'|'AWS_SECRET_KEY'|'CA_HEALTH_NUMBER'|'CA_SOCIAL_INSURANCE_NUMBER'|'CREDIT_DEBIT_CARD_CVV'|'CREDIT_DEBIT_CARD_EXPIRY'|'CREDIT_DEBIT_CARD_NUMBER'|'DRIVER_ID'|'EMAIL'|'INTERNATIONAL_BANK_ACCOUNT_NUMBER'|'IP_ADDRESS'|'LICENSE_PLATE'|'MAC_ADDRESS'|'NAME'|'PASSWORD'|'PHONE'|'PIN'|'SWIFT_CODE'|'UK_NATIONAL_HEALTH_SERVICE_NUMBER'|'UK_NATIONAL_INSURANCE_NUMBER'|'UK_UNIQUE_TAXPAYER_REFERENCE_NUMBER'|'URL'|'USERNAME'|'US_BANK_ACCOUNT_NUMBER'|'US_BANK_ROUTING_NUMBER'|'US_INDIVIDUAL_TAX_IDENTIFICATION_NUMBER'|'US_PASSPORT_NUMBER'|'US_SOCIAL_SECURITY_NUMBER'|'VEHICLE_IDENTIFICATION_NUMBER',
                                        'action': 'ANONYMIZED'|'BLOCKED'
                                    },
                                ],
                                'regexes': [
                                    {
                                        'name': 'string',
                                        'match': 'string',
                                        'regex': 'string',
                                        'action': 'ANONYMIZED'|'BLOCKED'
                                    },
                                ]
                            },
                            'contextualGroundingPolicy': {
                                'filters': [
                                    {
                                        'type': 'GROUNDING'|'RELEVANCE',
                                        'threshold': 123.0,
                                        'score': 123.0,
                                        'action': 'BLOCKED'|'NONE'
                                    },
                                ]
                            }
                        }
                    },
                    'outputAssessments': {
                        'string': [
                            {
                                'topicPolicy': {
                                    'topics': [
                                        {
                                            'name': 'string',
                                            'type': 'DENY',
                                            'action': 'BLOCKED'
                                        },
                                    ]
                                },
                                'contentPolicy': {
                                    'filters': [
                                        {
                                            'type': 'INSULTS'|'HATE'|'SEXUAL'|'VIOLENCE'|'MISCONDUCT'|'PROMPT_ATTACK',
                                            'confidence': 'NONE'|'LOW'|'MEDIUM'|'HIGH',
                                            'action': 'BLOCKED'
                                        },
                                    ]
                                },
                                'wordPolicy': {
                                    'customWords': [
                                        {
                                            'match': 'string',
                                            'action': 'BLOCKED'
                                        },
                                    ],
                                    'managedWordLists': [
                                        {
                                            'match': 'string',
                                            'type': 'PROFANITY',
                                            'action': 'BLOCKED'
                                        },
                                    ]
                                },
                                'sensitiveInformationPolicy': {
                                    'piiEntities': [
                                        {
                                            'match': 'string',
                                            'type': 'ADDRESS'|'AGE'|'AWS_ACCESS_KEY'|'AWS_SECRET_KEY'|'CA_HEALTH_NUMBER'|'CA_SOCIAL_INSURANCE_NUMBER'|'CREDIT_DEBIT_CARD_CVV'|'CREDIT_DEBIT_CARD_EXPIRY'|'CREDIT_DEBIT_CARD_NUMBER'|'DRIVER_ID'|'EMAIL'|'INTERNATIONAL_BANK_ACCOUNT_NUMBER'|'IP_ADDRESS'|'LICENSE_PLATE'|'MAC_ADDRESS'|'NAME'|'PASSWORD'|'PHONE'|'PIN'|'SWIFT_CODE'|'UK_NATIONAL_HEALTH_SERVICE_NUMBER'|'UK_NATIONAL_INSURANCE_NUMBER'|'UK_UNIQUE_TAXPAYER_REFERENCE_NUMBER'|'URL'|'USERNAME'|'US_BANK_ACCOUNT_NUMBER'|'US_BANK_ROUTING_NUMBER'|'US_INDIVIDUAL_TAX_IDENTIFICATION_NUMBER'|'US_PASSPORT_NUMBER'|'US_SOCIAL_SECURITY_NUMBER'|'VEHICLE_IDENTIFICATION_NUMBER',
                                            'action': 'ANONYMIZED'|'BLOCKED'
                                        },
                                    ],
                                    'regexes': [
                                        {
                                            'name': 'string',
                                            'match': 'string',
                                            'regex': 'string',
                                            'action': 'ANONYMIZED'|'BLOCKED'
                                        },
                                    ]
                                },
                                'contextualGroundingPolicy': {
                                    'filters': [
                                        {
                                            'type': 'GROUNDING'|'RELEVANCE',
                                            'threshold': 123.0,
                                            'score': 123.0,
                                            'action': 'BLOCKED'|'NONE'
                                        },
                                    ]
                                }
                            },
                        ]
                    }
                }
            }
        },
        'internalServerException': {
            'message': 'string'
        },
        'modelStreamErrorException': {
            'message': 'string',
            'originalStatusCode': 123,
            'originalMessage': 'string'
        },
        'validationException': {
            'message': 'string'
        },
        'throttlingException': {
            'message': 'string'
        }
    })
}

Response Structure

  • (dict) --

    • stream (:class:`.EventStream`) --

      The output stream that the model generated.

      • messageStart (dict) --

        Message start information.

        • role (string) --

          The role for the message.

      • contentBlockStart (dict) --

        Start information for a content block.

        • start (dict) --

          Start information about a content block start event.

          • toolUse (dict) --

            Information about a tool that the model is requesting to use.

            • toolUseId (string) --

              The ID for the tool request.

            • name (string) --

              The name of the tool that the model is requesting to use.

        • contentBlockIndex (integer) --

          The index for a content block start event.

      • contentBlockDelta (dict) --

        The messages output content block delta.

        • delta (dict) --

          The delta for a content block delta event.

          • text (string) --

            The content text.

          • toolUse (dict) --

            Information about a tool that the model is requesting to use.

            • input (string) --

              The input for a requested tool.

        • contentBlockIndex (integer) --

          The block index for a content block delta event.

      • contentBlockStop (dict) --

        Stop information for a content block.

        • contentBlockIndex (integer) --

          The index for a content block.

      • messageStop (dict) --

        Message stop information.

        • stopReason (string) --

          The reason why the model stopped generating output.

        • additionalModelResponseFields (:ref:`document<document>`) --

          The additional model response fields.

      • metadata (dict) --

        Metadata for the converse output stream.

        • usage (dict) --

          Usage information for the conversation stream event.

          • inputTokens (integer) --

            The number of tokens sent in the request to the model.

          • outputTokens (integer) --

            The number of tokens that the model generated for the request.

          • totalTokens (integer) --

            The total of input tokens and tokens generated by the model.

        • metrics (dict) --

          The metrics for the conversation stream metadata event.

          • latencyMs (integer) --

            The latency for the streaming request, in milliseconds.

        • trace (dict) --

          The trace object in the response from ConverseStream that contains information about the guardrail behavior.

          • guardrail (dict) --

            The guardrail trace object.

            • modelOutput (list) --

              The output from the model.

              • (string) --

            • inputAssessment (dict) --

              The input assessment.

              • (string) --

                • (dict) --

                  A behavior assessment of the guardrail policies used in a call to the Converse API.

                  • topicPolicy (dict) --

                    The topic policy.

                    • topics (list) --

                      The topics in the assessment.

                      • (dict) --

                        Information about a topic guardrail.

                        • name (string) --

                          The name for the guardrail.

                        • type (string) --

                          The type behavior that the guardrail should perform when the model detects the topic.

                        • action (string) --

                          The action the guardrail should take when it intervenes on a topic.

                  • contentPolicy (dict) --

                    The content policy.

                    • filters (list) --

                      The content policy filters.

                      • (dict) --

                        The content filter for a guardrail.

                        • type (string) --

                          The guardrail type.

                        • confidence (string) --

                          The guardrail confidence.

                        • action (string) --

                          The guardrail action.

                  • wordPolicy (dict) --

                    The word policy.

                    • customWords (list) --

                      Custom words in the assessment.

                      • (dict) --

                        A custom word configured in a guardrail.

                        • match (string) --

                          The match for the custom word.

                        • action (string) --

                          The action for the custom word.

                    • managedWordLists (list) --

                      Managed word lists in the assessment.

                      • (dict) --

                        A managed word configured in a guardrail.

                        • match (string) --

                          The match for the managed word.

                        • type (string) --

                          The type for the managed word.

                        • action (string) --

                          The action for the managed word.

                  • sensitiveInformationPolicy (dict) --

                    The sensitive information policy.

                    • piiEntities (list) --

                      The PII entities in the assessment.

                      • (dict) --

                        A Personally Identifiable Information (PII) entity configured in a guardrail.

                        • match (string) --

                          The PII entity filter match.

                        • type (string) --

                          The PII entity filter type.

                        • action (string) --

                          The PII entity filter action.

                    • regexes (list) --

                      The regex queries in the assessment.

                      • (dict) --

                        A Regex filter configured in a guardrail.

                        • name (string) --

                          The regex filter name.

                        • match (string) --

                          The regesx filter match.

                        • regex (string) --

                          The regex query.

                        • action (string) --

                          The region filter action.

                  • contextualGroundingPolicy (dict) --

                    The contextual grounding policy used for the guardrail assessment.

                    • filters (list) --

                      The filter details for the guardrails contextual grounding filter.

                      • (dict) --

                        The details for the guardrails contextual grounding filter.

                        • type (string) --

                          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 (string) --

                          The action performed by the guardrails contextual grounding filter.

            • outputAssessments (dict) --

              the output assessments.

              • (string) --

                • (list) --

                  • (dict) --

                    A behavior assessment of the guardrail policies used in a call to the Converse API.

                    • topicPolicy (dict) --

                      The topic policy.

                      • topics (list) --

                        The topics in the assessment.

                        • (dict) --

                          Information about a topic guardrail.

                          • name (string) --

                            The name for the guardrail.

                          • type (string) --

                            The type behavior that the guardrail should perform when the model detects the topic.

                          • action (string) --

                            The action the guardrail should take when it intervenes on a topic.

                    • contentPolicy (dict) --

                      The content policy.

                      • filters (list) --

                        The content policy filters.

                        • (dict) --

                          The content filter for a guardrail.

                          • type (string) --

                            The guardrail type.

                          • confidence (string) --

                            The guardrail confidence.

                          • action (string) --

                            The guardrail action.

                    • wordPolicy (dict) --

                      The word policy.

                      • customWords (list) --

                        Custom words in the assessment.

                        • (dict) --

                          A custom word configured in a guardrail.

                          • match (string) --

                            The match for the custom word.

                          • action (string) --

                            The action for the custom word.

                      • managedWordLists (list) --

                        Managed word lists in the assessment.

                        • (dict) --

                          A managed word configured in a guardrail.

                          • match (string) --

                            The match for the managed word.

                          • type (string) --

                            The type for the managed word.

                          • action (string) --

                            The action for the managed word.

                    • sensitiveInformationPolicy (dict) --

                      The sensitive information policy.

                      • piiEntities (list) --

                        The PII entities in the assessment.

                        • (dict) --

                          A Personally Identifiable Information (PII) entity configured in a guardrail.

                          • match (string) --

                            The PII entity filter match.

                          • type (string) --

                            The PII entity filter type.

                          • action (string) --

                            The PII entity filter action.

                      • regexes (list) --

                        The regex queries in the assessment.

                        • (dict) --

                          A Regex filter configured in a guardrail.

                          • name (string) --

                            The regex filter name.

                          • match (string) --

                            The regesx filter match.

                          • regex (string) --

                            The regex query.

                          • action (string) --

                            The region filter action.

                    • contextualGroundingPolicy (dict) --

                      The contextual grounding policy used for the guardrail assessment.

                      • filters (list) --

                        The filter details for the guardrails contextual grounding filter.

                        • (dict) --

                          The details for the guardrails contextual grounding filter.

                          • type (string) --

                            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 (string) --

                            The action performed by the guardrails contextual grounding filter.

      • internalServerException (dict) --

        An internal server error occurred. Retry your request.

        • message (string) --

      • modelStreamErrorException (dict) --

        A streaming error occurred. Retry your request.

        • message (string) --

        • originalStatusCode (integer) --

          The original status code.

        • originalMessage (string) --

          The original message.

      • validationException (dict) --

        Input validation failed. Check your request parameters and retry the request.

        • message (string) --

      • throttlingException (dict) --

        The number of requests exceeds the limit. Resubmit your request later.

        • message (string) --