public interface SafetyFilter

Pre-flight gate that inspects messages before they’re sent to the model. Implementations may call a moderation API, run a local profanity match, or anything else. Returning a non-null reason blocks the chat call and propagates an LlmInvalidRequestException.

Fields

public static final SafetyFilter ALLOW_ALLA built-in filter that allows everything.

Methods

public abstract String check(List<ChatMessage> messages)Returns null to allow the call, or a human-readable reason string to block it.

Field details

ALLOW_ALL

public static final SafetyFilter ALLOW_ALL
A built-in filter that allows everything. Useful as a default or as a base for composition. Use SafetyFilters.openai(key) (in com.codename1.ai.filters or a separate cn1lib) for the OpenAI Moderation gate.

Method details

check

public abstract String check(List<ChatMessage> messages)
Returns null to allow the call, or a human-readable reason string to block it.

Parameters

messages List<ChatMessage>
immutable request conversation

Returns

null to allow submission, otherwise the rejection reason