Claus Ibsen created CAMEL-27694:
-----------------------------------

             Summary: camel-aws-bedrock - guardrailTrace=true switches the 
stream guardrail to asynchronous processing
                 Key: CAMEL-27694
                 URL: https://issues.apache.org/jira/browse/CAMEL-27694
             Project: Camel
          Issue Type: Bug
          Components: camel-aws2
            Reporter: Claus Ibsen
             Fix For: 4.24.0


In {{BedrockProducer.converseStream()}}, when the guardrail comes from the 
endpoint options ({{guardrailIdentifier}}, {{guardrailVersion}}, 
{{guardrailTrace}}), the producer builds the {{GuardrailStreamConfiguration}} 
with:

{code:java}
.streamProcessingMode(getConfiguration().isGuardrailTrace()
        ? GuardrailStreamProcessingMode.ASYNC
        : GuardrailStreamProcessingMode.SYNC)
{code}

So {{guardrailTrace=true}}, which should only ask Bedrock for the guardrail 
trace, also switches the guardrail on the stream from synchronous to 
asynchronous processing.

The AWS docs (Configure streaming response behavior, 
https://docs.aws.amazon.com/bedrock/latest/userguide/guardrails-streaming.html) 
describe the two modes: in the default synchronous mode the guardrail buffers 
and evaluates the chunks before they are sent to the caller; in asynchronous 
mode the chunks are sent at once while the guardrail evaluates them in the 
background, so chunks may contain content the guardrail would block until the 
scan completes, and masking of sensitive information is not supported. Turning 
on the trace therefore silently changes how the guardrail filters the stream.

The CamelAwsBedrockGuardrailConfig header path is not affected: a 
{{GuardrailStreamConfiguration}} header is used as given, and a 
{{GuardrailConfiguration}} header is converted without a processing mode 
(Bedrock default, sync).

h4. Proposed change
* Add an endpoint option {{guardrailStreamProcessingMode}} (enum {{sync}} / 
{{async}}, the values of the SDK {{GuardrailStreamProcessingMode}}), default 
{{sync}}, used by converseStream for the guardrail of the 
{{guardrailIdentifier}} option.
* {{guardrailTrace}} only sets the trace.
* Upgrade guide: routes with {{guardrailTrace=true}} now use synchronous 
processing unless {{guardrailStreamProcessingMode=async}} is set.

_Claude Code on behalf of Claus Ibsen_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to