:doc:`AgentsforBedrockRuntime <../../bedrock-agent-runtime>` / Client / optimize_prompt

***************
optimize_prompt
***************



.. py:method:: AgentsforBedrockRuntime.Client.optimize_prompt(**kwargs)

  

  Optimizes a prompt for the task that you specify. For more information, see `Optimize a prompt <https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-management-optimize.html>`__ in the `Amazon Bedrock User Guide <https://docs.aws.amazon.com/bedrock/latest/userguide/what-is-service.html>`__.

  

  See also: `AWS API Documentation <https://docs.aws.amazon.com/goto/WebAPI/bedrock-agent-runtime-2023-07-26/OptimizePrompt>`_  


  **Request Syntax**
  ::

    response = client.optimize_prompt(
        input={
            'textPrompt': {
                'text': 'string'
            }
        },
        targetModelId='string'
    )
    
  :type input: dict
  :param input: **[REQUIRED]** 

    Contains the prompt to optimize.

    .. note::    This is a Tagged Union structure. Only one of the     following top level keys can be set: ``textPrompt``. 

  
    - **textPrompt** *(dict) --* 

      Contains information about the text prompt to optimize.

      

    
      - **text** *(string) --* **[REQUIRED]** 

        The text in the text prompt to optimize.

        

      
    
  
  :type targetModelId: string
  :param targetModelId: **[REQUIRED]** 

    The unique identifier of the model that you want to optimize the prompt for.

    

  
  
  :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**

    
    ::

      {
          'optimizedPrompt': EventStream({
              'accessDeniedException': {
                  'message': 'string'
              },
              'analyzePromptEvent': {
                  'message': 'string'
              },
              'badGatewayException': {
                  'message': 'string',
                  'resourceName': 'string'
              },
              'dependencyFailedException': {
                  'message': 'string',
                  'resourceName': 'string'
              },
              'internalServerException': {
                  'message': 'string',
                  'reason': 'string'
              },
              'optimizedPromptEvent': {
                  'optimizedPrompt': {
                      'textPrompt': {
                          'text': 'string'
                      }
                  }
              },
              'throttlingException': {
                  'message': 'string'
              },
              'validationException': {
                  'message': 'string'
              }
          })
      }
      
    **Response Structure**

    

    - *(dict) --* 
      

      - **optimizedPrompt** (:class:`.EventStream`) -- 

        The prompt after being optimized for the task.

        
        

        - **accessDeniedException** *(dict) --* 

          The request is denied because of missing access permissions. Check your permissions and retry your request.

          
          

          - **message** *(string) --* 
      
        

        - **analyzePromptEvent** *(dict) --* 

          An event in which the prompt was analyzed in preparation for optimization.

          
          

          - **message** *(string) --* 

            A message describing the analysis of the prompt.

            
      
        

        - **badGatewayException** *(dict) --* 

          There was an issue with a dependency due to a server issue. Retry your request.

          
          

          - **message** *(string) --* 
          

          - **resourceName** *(string) --* 

            The name of the dependency that caused the issue, such as Amazon Bedrock, Lambda, or STS.

            
      
        

        - **dependencyFailedException** *(dict) --* 

          There was an issue with a dependency. Check the resource configurations and retry the request.

          
          

          - **message** *(string) --* 
          

          - **resourceName** *(string) --* 

            The name of the dependency that caused the issue, such as Amazon Bedrock, Lambda, or STS.

            
      
        

        - **internalServerException** *(dict) --* 

          An internal server error occurred. Retry your request.

          
          

          - **message** *(string) --* 
          

          - **reason** *(string) --* 

            The reason for the exception. If the reason is ``BEDROCK_MODEL_INVOCATION_SERVICE_UNAVAILABLE``, the model invocation service is unavailable. Retry your request.

            
      
        

        - **optimizedPromptEvent** *(dict) --* 

          An event in which the prompt was optimized.

          
          

          - **optimizedPrompt** *(dict) --* 

            Contains information about the optimized prompt.

            .. note::    This is a Tagged Union structure. Only one of the     following top level keys will be set: ``textPrompt``.     If a client receives an unknown member it will     set ``SDK_UNKNOWN_MEMBER`` as the top level key,     which maps to the name or tag of the unknown     member. The structure of ``SDK_UNKNOWN_MEMBER`` is     as follows::

                        'SDK_UNKNOWN_MEMBER': {'name': 'UnknownMemberName'}


          
            

            - **textPrompt** *(dict) --* 

              Contains information about the text in the prompt that was optimized.

              
              

              - **text** *(string) --* 

                The text in the text prompt to optimize.

                
          
        
      
        

        - **throttlingException** *(dict) --* 

          Your request was throttled because of service-wide limitations. Resubmit your request later or in a different region. You can also purchase `Provisioned Throughput <https://docs.aws.amazon.com/bedrock/latest/userguide/prov-throughput.html>`__ to increase the rate or number of tokens you can process.

          
          

          - **message** *(string) --* 
      
        

        - **validationException** *(dict) --* 

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

          
          

          - **message** *(string) --* 
      
    
  
  **Exceptions**
  
  *   :py:class:`AgentsforBedrockRuntime.Client.exceptions.ValidationException`

  
  *   :py:class:`AgentsforBedrockRuntime.Client.exceptions.InternalServerException`

  
  *   :py:class:`AgentsforBedrockRuntime.Client.exceptions.DependencyFailedException`

  
  *   :py:class:`AgentsforBedrockRuntime.Client.exceptions.BadGatewayException`

  
  *   :py:class:`AgentsforBedrockRuntime.Client.exceptions.ThrottlingException`

  
  *   :py:class:`AgentsforBedrockRuntime.Client.exceptions.AccessDeniedException`

  