Skip to content

Fix validation error for file parser image elements#235

Merged
mattapperson merged 1 commit intoOpenRouterTeam:mainfrom
smorimoto:fix/file-content-text-optional
Nov 24, 2025
Merged

Fix validation error for file parser image elements#235
mattapperson merged 1 commit intoOpenRouterTeam:mainfrom
smorimoto:fix/file-content-text-optional

Conversation

@smorimoto
Copy link
Copy Markdown
Contributor

Problem

When the file-parser plugin processes PDFs containing images using the Mistral OCR engine, it returns annotations with a content array that includes both text and image elements. Image elements have the structure {"type":"image_url","image_url":{...}} without a text property, causing validation failures.

Solution

Make the text field optional in the file annotation content schema (lines 116 and 240 in src/chat/schemas.ts).

Changes

  • Modified text: z.string() to text: z.string().optional() in both non-stream and stream response schemas
  • Allows the schema to accept both text elements with text content and image elements without text content

Related

Builds upon #232 which added .passthrough() for forward compatibility.

The file-parser plugin returns content arrays containing both text
and image elements. Image elements (type: "image_url") do not have
a text property, causing validation errors.

This change makes the text field optional to support both element
types whilst maintaining backwards compatibility with text-only
content.

Fixes validation error: "Invalid input: expected string, received undefined"

Signed-off-by: Sora Morimoto <sora@morimoto.io>
@smorimoto smorimoto force-pushed the fix/file-content-text-optional branch from e64fb35 to a7cf99b Compare November 21, 2025 00:51
@prime7
Copy link
Copy Markdown

prime7 commented Nov 24, 2025

+1 this is needed

@mattapperson mattapperson merged commit 4a2ba11 into OpenRouterTeam:main Nov 24, 2025
2 checks passed
@smorimoto smorimoto deleted the fix/file-content-text-optional branch November 24, 2025 14:40
subtleGradient added a commit that referenced this pull request Nov 25, 2025
subtleGradient added a commit that referenced this pull request Nov 25, 2025
subtleGradient added a commit that referenced this pull request Nov 25, 2025
@github-actions github-actions bot mentioned this pull request Nov 25, 2025
kesavan-byte pushed a commit to osm-API/ai-sdk-provider that referenced this pull request Feb 13, 2026
…rTeam#235)

The file-parser plugin returns content arrays containing both text
and image elements. Image elements (type: "image_url") do not have
a text property, causing validation errors.

This change makes the text field optional to support both element
types whilst maintaining backwards compatibility with text-only
content.

Fixes validation error: "Invalid input: expected string, received undefined"

Signed-off-by: Sora Morimoto <sora@morimoto.io>
kesavan-byte pushed a commit to osm-API/ai-sdk-provider that referenced this pull request Feb 13, 2026
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.

3 participants