Skip to content

Commit 0513bc3

Browse files
llm: document why validate_message_list skips role alternation
Future readers (and users hitting vLLM-Mistral 400s) need a pointer to where the role-alternation constraint lives. Strict templates enforce user→assistant alternation server-side; OpenAI and Anthropic don't. Pre-rejecting at the client boundary would over-restrict the permissive case.
1 parent 48e7a55 commit 0513bc3

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

src/openarmature/llm/provider.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,18 @@ def validate_message_list(messages: Sequence[Message]) -> None:
9898
)
9999

100100
# System messages are only permitted at the first position. Per
101-
# spec §3 the conversation begins with at most one system message,
102-
# then alternates user/assistant/tool — a system message in the
103-
# middle of the list is a request error.
101+
# spec §3, at most one system message and only at the start of the
102+
# conversation. A system message in the middle of the list is a
103+
# request error.
104+
#
105+
# Note: this function does NOT enforce strict role alternation
106+
# (e.g., user → assistant → user). Some servers (notably vLLM with
107+
# Mistral templates, and other strict chat-template models) reject
108+
# non-alternating sequences server-side and return 400 — that
109+
# surfaces as ProviderInvalidRequest per §7, with the server's
110+
# error message preserved. Pre-rejecting at the client boundary
111+
# would over-restrict providers like OpenAI and Anthropic that
112+
# handle templating permissively.
104113
for idx, msg in enumerate(messages):
105114
if idx > 0 and isinstance(msg, SystemMessage):
106115
raise ProviderInvalidRequest(

0 commit comments

Comments
 (0)