Skip to content

Fix Draft and Chat "System messages are not allowed" error - #572

Merged
kcarnold merged 1 commit into
mainfrom
claude/draft-chat-system-message-error-ongv43
Jul 28, 2026
Merged

Fix Draft and Chat "System messages are not allowed" error#572
kcarnold merged 1 commit into
mainfrom
claude/draft-chat-system-message-error-ongv43

Conversation

@kcarnold

Copy link
Copy Markdown
Contributor

The bug

Draft and Chat failed on every request with:

Invalid prompt: System messages are not allowed in the prompt or messages fields. Use the instructions option instead.

Since ai@7, standardizePrompt throws InvalidPromptError when a role: 'system' message appears in messages — the system prompt has to travel as the instructions option instead. The failure happens client-side, before the request reaches the proxy, so nothing in the backend or the model config is involved.

Revise was already migrated (instructions: systemPrompt), which is why it kept working. Draft (buildMessages prepended a system message) and Chat (CHAT_SYSTEM_MESSAGE seeded at index 0 of the transcript) were not.

The fix

  • DraftbuildMessages now returns user messages only; its system prompt is exported as DRAFT_INSTRUCTIONS and passed as instructions on the generateFullText call.
  • Chat — the system prompt leaves the transcript entirely and becomes CHAT_INSTRUCTIONS, passed as instructions. The seeded messages are now doc-context + greeting, so withCurrentDocContext refreshes index 0 instead of index 1, and the visible transcript starts at the named SEEDED_MESSAGE_COUNT rather than a literal 3. What the writer sees is unchanged.

Verification

npm test (208 passing), npm run typecheck, and npm run style are all clean. New coverage:

  • src/api/__tests__/prompts.test.tsbuildMessages returns user messages only, and still carries prompt, brief, document, and selection.
  • src/pages/chat/__tests__/docContextMessage.test.ts — updated for the new indices, plus a case asserting no system message ever enters the transcript.

Both call shapes were also run end-to-end through the real ai@7 validator against a MockLanguageModelV3: they pass validation, and instructions arrives as exactly one system entry at the head of the model prompt — the same place the old system message occupied.

frontend/CLAUDE.md documents the rule so the next page doesn't reintroduce it.


Generated by Claude Code

ai@7 rejects a `role: 'system'` message inside `messages`
(InvalidPromptError: "System messages are not allowed in the prompt or
messages fields. Use the instructions option instead."), so every Draft
suggestion and every Chat turn failed before the request left the
browser. Revise already passed its system prompt as `instructions`,
which is why it kept working.

- Draft: `buildMessages` now returns user messages only; the system
  prompt is exported as `DRAFT_INSTRUCTIONS` and passed as
  `instructions`.
- Chat: the system prompt leaves the transcript entirely and becomes
  `CHAT_INSTRUCTIONS`. The seeded messages are now doc-context +
  greeting, so the doc-context refresh writes index 0 and the visible
  transcript starts at `SEEDED_MESSAGE_COUNT`.

Tests cover both shapes against the ai@7 validator, and frontend/CLAUDE.md
documents the rule.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013iq2h4nTQWWG4fYHmw1B4z
@kcarnold
kcarnold merged commit 62225bf into main Jul 28, 2026
9 of 10 checks passed
@kcarnold
kcarnold deleted the claude/draft-chat-system-message-error-ongv43 branch July 28, 2026 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants