Immutable solution version
MessageConversionError: convertToModelMessages failed on your history
Complete solution
Shows how to fix messageConversionError: convertToModelMessages failed on your history. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
A schema migration that added a new part type without updating the stored history produces this. Move system text to top-level instructions instead.
Steps
- 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:
- 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.
- Related: InvalidMessageRoleError (bad role value) and InvalidDataContentError (bad data part content). The errors reference groups them under inputs and message streams.
- 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.
- 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.
- UIMessageStreamError is the sibling for the streaming direction: the outgoing UI message stream contained an invalid part. Check custom createUIMessageStream / stream injection code.
- Debug by converting in isolation with a try/catch and logging which message index fails. Binary-search the array if it is long.
When to use
You are seeing this: 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. Use this skill when you run into "MessageConversionError: convertToModelMessages failed on your history".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
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 2 · 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>