Skip to content

fix: handle bare string for include_domains/exclude_domains in Zod schema search tools#910

Merged
miurla merged 1 commit into
miurla:mainfrom
simply24365:fix/include-domains-coercion
Jul 1, 2026
Merged

fix: handle bare string for include_domains/exclude_domains in Zod schema search tools#910
miurla merged 1 commit into
miurla:mainfrom
simply24365:fix/include-domains-coercion

Conversation

@simply24365

Copy link
Copy Markdown
Contributor

Summary

AI models sometimes return include_domains / exclude_domains as a bare
string ("reddit.com") instead of string[] (["reddit.com"]), causing
TypeError: f.join is not a function in search-section.tsx.

This was observed with the Xiaomi MIMO v2.5 model (OpenAI-compatible
endpoint), which does not enforce strict: true on function definitions.
The model can therefore produce type-invalid tool call arguments, which
Zod rejects at validation time — but the AI SDK still renders the raw
(unvalidated) input in the UI.

Changes

  1. lib/schema/search.tsx — Replaced z.array(z.string()) with
    z.union([z.string(), z.array(z.string())]) + .transform() so that
    bare strings are coerced into single-element arrays at Zod validation
    time, preventing the tool call from being rejected. Applied to both
    searchSchema and strictSearchSchema for include_domains and
    exclude_domains.

  2. components/search-section.tsx — Added Array.isArray guard
    before .join() as defense-in-depth.

Suggestion

This type of mismatch can affect any array-typed tool parameter. Consider
enabling strict: true on tools for providers that support it, or
implementing repairToolCall in ToolLoopAgent to automatically fix and
retry failed tool calls.

@vercel

vercel Bot commented Jul 1, 2026

Copy link
Copy Markdown

@simply24365 is attempting to deploy a commit to the morphic Team on Vercel.

A member of the Team first needs to authorize it.

@vercel

vercel Bot commented Jul 1, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
morphic Ready Ready Preview, Comment Jul 1, 2026 2:13pm

Request Review

@miurla miurla left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix and the clear write-up. LGTM!

@miurla miurla merged commit f6b6e41 into miurla:main Jul 1, 2026
7 checks passed
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