Skip to main content
For non-streaming Anthropic Messages calls, Averta checks final assistant text before the wrapped client returns it to your application. Output checks run only when the response does not contain tool_use blocks. If the model asks for a tool, the wrapper checks the tool call and returns control to your app for the native Anthropic tool loop.

Example

const message = await client.messages.create({
  model: process.env.ANTHROPIC_MODEL ?? "claude-sonnet-4-5",
  max_tokens: 512,
  messages: [
    {
      role: "user",
      content: "Write a customer-safe summary of the account recovery steps.",
    },
  ],
});
Before this call resolves, the wrapper extracts text content blocks from the assistant response and sends the combined text to the output checkpoint.

Outcomes

DecisionWrapper behavior
allowReturns the original Anthropic response.
blockThrows AvertaSdkError.
rewriteAsks Anthropic for a rewritten answer, then checks the rewritten output once more.

Rewrite Behavior

For rewrite, the wrapper builds a new non-streaming Anthropic request that:
  • keeps the original conversation
  • appends the unsafe assistant response
  • appends an Averta rewrite instruction as the next user message
  • removes tools, tool_choice, and stream
The rewritten answer is checked again with rewrite_attempt: 1. If that second output is blocked, the wrapper throws.

Decision Callback

client = wrapAnthropic(client, {
  onDecision(event) {
    if (event.checkpointType === "output") {
      console.log(event.rewriteAttempt, event.decision.decision);
    }
  },
});

Limits

Streaming is not supported in the current Anthropic wrapper, so output checks and rewrites are available only for non-streaming messages.create(...) calls.