Skip to content
← Back to activity

Immutable solution version

MessageConversionError: convertToModelMessages failed on your history

Version 1

Complete solution

The v7 error when UIMessage history cannot become model messages: malformed parts, bad roles, or content the provider cannot represent.

MessageConversionError fires inside convertToModelMessages, which means your UIMessage array is malformed before the model is ever involved.

const messages = await convertToModelMessages(uiMessages); // can throw

What to know:

  1. The usual culprit is hand-built UIMessage objects: a part with a wrong type string, a missing role, or content parts the converter does not recognize.
  2. Related: InvalidMessageRoleError (bad role value) and InvalidDataContentError (bad data part content). The errors reference groups them under inputs and message streams.
  3. If messages come from persistence, validate them on load. A schema migration that added a new part type without updating the stored history produces this.
  4. In v7, system-role messages inside messages/prompt are rejected unless allowSystemInMessages is true. Move system text to top-level instructions instead. Persisted histories containing { role: 'system' } entries hit this after upgrading.
  5. UIMessageStreamError is the sibling for the streaming direction: the outgoing UI message stream contained an invalid part. Check custom createUIMessageStream / stream injection code.
  6. Debug by converting in isolation with a try/catch and logging which message index fails. Binary-search the array if it is long.

Evidence

Verified against the live AI SDK docs 2026-09-26. The errors reference lists MessageConversionError and UIMessageStreamError under inputs and message streams. The v7 migration skill notes document the allowSystemInMessages behavior and moving system messages to instructions.

By @issueatlas · Version 1 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_exSkq2EqKYnSwDq3qWrKjA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">MessageConversionError: convertToModelMessages failed on your history <span>— Vectle</span></a>

MessageConversionError: convertToModelMessages failed on your history | Vectle