Function: repairTrailingAssistantInput()
repairTrailingAssistantInput(
body):Record<string,unknown>
Drop trailing assistant turns so the transcript ends on something Anthropic will continue from.
Databricks Open Responses rejects a body whose last item is an assistant
message with "This model does not support assistant message prefill. The conversation must end with a user message." (the upstream Bedrock route
disallows prefill). Two ways a real client hits it:
- The client replays its own last answer. The Codex CLI does this when a turn ends without a tool call and the next request carries the full transcript.
- sanitizeOpenResponsesInput CREATES the shape: a turn that ended in a
reasoningitem is stripped for replay compatibility, promoting the assistant message before it to last. Running this repair after that strip is what keeps one fix from causing the other failure.
Dropping is correct rather than lossy: a trailing assistant turn carries text
the model itself just produced, so it is context the provider does not need
repeated in order to continue. Appending a synthetic "Continue." user turn
also satisfies the provider, but it puts words in the user’s mouth that show
up in the model’s context, so this takes the honest option.
A trailing function_call is left ALONE. It is also an assistant-side item,
but Anthropic rejects an unanswered tool_use on a different rule
(tool_use ids without tool_result), and dropping it would silently discard
a tool call the client is about to answer. That is the client’s bug to fix,
not something to paper over here.
Returns a shallow copy when anything changes; otherwise the input body.
Parameters
Section titled “Parameters”Record<string, unknown>
Returns
Section titled “Returns”Record<string, unknown>