mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #3015] [Issue]: parametersSchema accepted with no JSON-Schema validation; malformed nested schemas reach the LLM provider verbatim #1588
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#1588
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kolacheee on GitHub (Jun 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3015
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
The Zod create/update schema types
parametersSchemaasz.record(z.unknown()).default({})— any JSON object is accepted, with no validation of JSON-Schema shape. The only structural validation (validateToolSchema) runs at generation time and checks ONLY the root-leveltype,properties, andrequired. It does NOT validate nested property definitions. So a tool whoseparametersSchemais e.g.{"type":"object","properties":{"foo":{"type":"notatype"}}}passesvalidateToolSchemaand is forwarded to the provider verbatim. With a strict provider this can 400 the whole generation request (taking down all tools for that turn), not just the bad tool. Via the Tool Editor UI this is hard to trigger (the type dropdown is constrained), but it is fully reachable through the raw POST/PATCH API and through import.How to reproduce (try it yourself)
POST /custom-toolswith{"name":"bad_schema","description":"x","executionType":"static","staticResult":"ok","parametersSchema":{"type":"object","properties":{"foo":{"type":"notatype"}}}}.validateToolSchemapasses).You'll see: the provider rejects the tools payload because property
foo.typeis invalid; the whole generation fails rather than silently skipping just this tool.Expected: a single malformed custom tool is skipped (with a server warn) instead of poisoning the entire provider tools array; ideally the raw API also returns a clear 400 at create time.
Where it is
Zod default at
packages/shared/src/schemas/custom-tool.schema.ts:15; CRUD boundary with no schema validation atpackages/server/src/routes/custom-tools.routes.ts:32,46; root-onlyvalidateToolSchemaatpackages/server/src/services/generation/tool-resolution-runtime.ts:230-260and verbatim push at:321-328; verbatim forward to provider atpackages/server/src/services/llm/providers/openai.provider.ts:884,1136,1550-1555; unvalidated import path atpackages/client/src/lib/custom-tool-transfer.ts:46-57,82-121,200-217.What's happening
No JSON-Schema shape validation exists at the CRUD or import boundary (Zod accepts any record), and the resolution-time
validateToolSchemaonly inspects the root object, leaving nested property definitions unchecked before the schema is handed to the provider.Suggested fix
Make
validateToolSchemaintool-resolution-runtime.tsrecurse into property definitions, with a PERMISSIVE ruleset. The existing per-tool try/catch (lines 305-337) already skips an offending tool and logs a warn, so a recursive validator turns a malformed nested property into a skip instead of a verbatim push. Add a recursivevalidateParameterProperty(prop, path)that:typeis present-but-invalid (not one of string/number/integer/boolean/array/object),enum, a structurally-wrongitems, a non-object nestedproperties, or a non-string-arrayrequired,itemsand nestedproperties,and call it for each root property after the existing root checks. Do NOT require
description, do NOT reject unknown/extra keywords (oneOf,additionalProperties,default,minimum,maximum,multipleOfmust pass through), and accept properties with no explicittype, so the real schemas the system already emits still pass (e.g.spotify_playwithoneOf+additionalProperties:false,save_lorebook_entrywitharray+items+enum). This fixes both new tools and any malformed row already persisted, with no Zod/route change.Regression avoided: CRUD-boundary-only validation was rejected as incomplete — it only guards new writes, leaving pre-existing malformed rows (from prior raw-API writes or imports) to still poison the whole request at generation time. A strict/over-tight Zod mirror at the boundary would also reject legitimate
oneOf/additionalProperties/items/enumschemas on the import path. The recursive resolution-time validator is permissive (type optional, no required description, unknown keys allowed), so it only rejects present-but-invalid property types and structurally-brokenitems/enum/properties/required— exactly the malformed cases. Optional defense-in-depth: call the same permissive ruleset at the CRUD boundary to return a 400 early; if added, reuse this exact ruleset, not a stricter mirror.Related: this touches the same
validateToolSchemafunction as the empty-{}-schema drop (filed as a sibling issue). Coordinate the two — this one adds nested validation; the other relaxes the empty case.AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.
@SpicyMarinara commented on GitHub (Jun 29, 2026):
Fixed in merged staging PR #3018.