Validates that every tool result in a conversation answers a tool call the model actually made.
The contract providers enforce: a tool_result is only meaningful next to the assistant turn
whose tool_use / tool_calls it answers. The easy way to break it is to append the model's
reply to the conversation WITHOUT copying ChatCompletionMessage.toolCalls onto the
assistant ChatMessage, then append the results — the calls vanish and the results are
orphaned. Anthropic rejects that outright, and the provider's own error names an opaque id rather
than the mistake, so this catches it at the MJ boundary with a message that says what to fix.
Only runs where it can find a problem: conversations with no tool turns are untouched.
Validates that every tool result in a conversation answers a tool call the model actually made.
The contract providers enforce: a
tool_resultis only meaningful next to the assistant turn whosetool_use/tool_callsit answers. The easy way to break it is to append the model's reply to the conversation WITHOUT copying ChatCompletionMessage.toolCalls onto the assistant ChatMessage, then append the results — the calls vanish and the results are orphaned. Anthropic rejects that outright, and the provider's own error names an opaque id rather than the mistake, so this catches it at the MJ boundary with a message that says what to fix.Only runs where it can find a problem: conversations with no tool turns are untouched.