Skip to content

Expose client-facing chat sanitization hooks separate from persistence sanitization #1744

@arthurfiorette

Description

@arthurfiorette

Today Think & AiChatAgent allows to sanitize persisted messages via sanitizeMessageForPersistence(), but doesn't expose a hook to sanitize what is exposed to the client. For example, I might want to hide from the frontend a tool output. I know this does not 100% guarantee and the user might just ask like "what was that tool output", but for that we can add more system prompts and other anti-jailbreaks.

Something like:

protected sanitizeMessageForClient(message: UIMessage): UIMessage

// and

protected sanitizeChatResponseChunkForClient(
  chunk: UIMessageChunk
): UIMessageChunk | null

or just a

protected sanitizeOutgoingChatFrame(
  frame: OutgoingMessage
): OutgoingMessage | null

Ideally they should cover CF_AGENT_USE_CHAT_RESPONSE, CF_AGENT_CHAT_MESSAGES, /get-messages...

A more declarative option like:

clientTranscriptPolicy = {
  stripToolOutputs: true,
  stripToolInputs: true,
  stripProviderMetadata: true,
}

would also be welcomed :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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