Skip to content

Add ModerationAdvisor for ChatClient #5717

@ultramancode

Description

@ultramancode

Add ModerationAdvisor for ChatClient


Expected Behavior

It would be helpful to have a built-in ModerationAdvisor that integrates ModerationModel into the ChatClient advisor chain for both non-streaming and streaming flows.

  • It evaluates user input before model invocation.
  • If moderation is flagged, it returns a configured fallback response.
  • If not flagged, it continues to the next advisor.
  • It is configurable with builder options such as order, failureResponse, and failure policy (e.g. failOpen).

Example:

ModerationAdvisor moderationAdvisor = ModerationAdvisor.builder()
        .moderationModel(moderationModel)
        .failureResponse("I'm unable to respond to that due to safety policy.")
        .order(0)
        .failOpen(true)
        .build();

ChatClientResponse response = chatClient.prompt()
        .advisors(moderationAdvisor)
        .user(userInput)
        .call()
        .chatClientResponse();

Current Behavior

There is currently no built-in advisor that gates ChatClient requests via ModerationModel.

  • SafeGuardAdvisor exists, but it is rule-based/keyword-based.
  • For model-based moderation, users currently need to manually call moderation APIs and wire the logic in both call and stream paths.
  • This is workable, but tends to add repeated application-level code.

Context

A built-in ModerationAdvisor would provide a reusable way to apply moderation in the advisor chain.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions