Skip to content

fix: apply min/max modifiers to ZodNumber in secureZodParser - #6672

Open
Osamaali313 wants to merge 1 commit into
FlowiseAI:mainfrom
Osamaali313:bugfix/zodnumber-min-max
Open

fix: apply min/max modifiers to ZodNumber in secureZodParser#6672
Osamaali313 wants to merge 1 commit into
FlowiseAI:mainfrom
Osamaali313:bugfix/zodnumber-min-max

Conversation

@Osamaali313

Copy link
Copy Markdown

Description

SecureZodSchemaParser.applyModifiers (packages/components/src/secureZodParser.ts) applies .min() / .max() for ZodString and ZodArray, but has no ZodNumber branch — so numeric bounds are silently dropped:

case 'max':
    if (modifier.args[0] !== undefined) {
        if (zodType._def?.typeName === 'ZodString') { ... }
        else if (zodType._def?.typeName === 'ZodArray') { ... }
        // no ZodNumber branch
    }

A user schema like z.number().min(0).max(100) therefore accepts out-of-range values (e.g. 999, -50). This parser is used by the Structured Output Parser (Advanced) and Custom Tool nodes, so LLM structured output / tool arguments that the author explicitly bounded are passed through unvalidated. The sibling int case already branches on ZodNumber, confirming numeric modifiers are meant to apply.

Repro (schema z.object({ score: z.number().min(0).max(100) })): before, score: 999 and score: -50 are accepted; after, they're rejected (too_big / too_small), while a z.string().max(5) control already worked.

Fix

Add the missing ZodNumber branch to both min and max:

} else if (zodType._def?.typeName === 'ZodNumber') {
    zodType = (zodType as z.ZodNumber).max(modifier.args[0])   // and .min(...) in the min case
}

String/array bounds are unchanged. (There was no existing test file for secureZodParser.ts; happy to add one if you'd like.)

applyModifiers handled .min()/.max() for ZodString and ZodArray but not
ZodNumber, so numeric bounds in a user schema (e.g. z.number().min(0).max(100))
were silently discarded and out-of-range values passed validation. The sibling
`int` case already branches on ZodNumber, confirming numeric modifiers are
meant to apply. Add the missing ZodNumber branch to both min and max.
Copilot AI review requested due to automatic review settings July 26, 2026 20:32
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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