moderate

open suspend override fun moderate(prompt: Prompt, model: LLModel): ModerationResult(source)

Moderates the provided prompt using AWS Bedrock Guardrails.

Unlike other LLM operations, moderation in Bedrock uses the Guardrails API which is model-independent. The guardrails are configured at the client level via moderationGuardrailsSettings and evaluate content based on those guardrail rules, not based on any specific model's capabilities.

This means:

  • The model parameter is not used in this implementation

  • Any Bedrock model can be passed, but it won't affect the moderation result

  • The moderation behavior is determined entirely by the guardrail configuration

The method evaluates both input (user messages) and output (assistant responses) against the configured guardrails and determines if either is harmful.

Requires moderationGuardrailsSettings to be configured when creating this BedrockLLMClient.

Return

A ModerationResult indicating whether the content is harmful and a map of categorized moderation results based on the guardrail filters.

Parameters

prompt

The prompt containing messages to be evaluated for harmful content.

model

The language model (unused in Bedrock - moderation is model-independent).

See also

Throws

if moderation guardrails settings are not provided or if the prompt is empty.