Skip to content
1 min read · 178 words

Function: enforceConverseAlternation()

ts
function enforceConverseAlternation(
  messages: ConverseMessage[],
  policy?: "merge" | "filler" | "reject",
): ConverseMessage[];

Defined in: src/batteries/llm/bedrock_converse/helpers.ts:254

Apply Converse's strict userassistant alternation to an already-ordered turn list.

Parameters

ParameterTypeDefault value
messagesConverseMessage[]undefined
policy"merge" | "filler" | "reject"'merge'

Returns

ConverseMessage[]

Remarks

Exported and separately testable because it is the single most consequential transformation in this battery, and the one a gateway would otherwise perform invisibly.

  • 'merge' concatenates consecutive same-role turns' content blocks. Lossless: the same blocks in the same order, in one turn — exactly what Converse would have accepted had the caller written it that way.
  • 'filler' inserts a placeholder opposite-role turn. LOSSIER — it fabricates model output that never existed — and offered only for callers who need positional stability across turns.
  • 'reject' returns the list untouched so Converse's own error surfaces. Use this when AUDITING: a repair applied before dispatch is invisible in the response, which makes a gateway's fix indistinguishable from a vendor's tolerance.