[GH-ISSUE #3007] [Issue]: Custom tool with empty {} parametersSchema (the schema default) is silently dropped from generation #1579

Closed
opened 2026-10-21 05:39:40 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kolacheee on GitHub (Jun 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3007

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong

validateToolSchema rejects a schema that has neither a root type nor properties. The Zod schema for custom tools defaults parametersSchema to {} when the field is omitted. A custom tool stored with parametersSchema = {} therefore fails validation in loadToolDefinitions, is caught, logged only as a server warn, and silently skipped — so the tool never reaches the model even though it shows as enabled. This is the legitimate "tool takes no parameters" case, which the client UI handles fine (it emits { type: "object", properties: {}, required: [] }). The result is an inconsistency: a no-parameter tool created in the UI works, but the same tool created via the REST API (omitting parametersSchema) or imported from a package lacking a schema is silently non-functional.

How to reproduce (try it yourself)

  1. POST /custom-tools with a body that omits parametersSchema, e.g. { "name": "get_time", "description": "...", "executionType": "static", "staticResult": "now" }. Zod applies .default({}) and the tool is stored with parametersSchema = "{}". (Or import a tool package whose source has no/invalid parametersSchema.)
  2. Start a generation with tools enabled (enableTools=true).
  3. Have the model attempt to call the tool.

You'll see: validateToolSchema({}) throws, the catch block deletes the registration and logs a warn, and the tool is omitted from the definitions sent to the model. The model never sees the tool and there is no user-facing error.

Expected: a zero-parameter custom tool is offered to the model regardless of whether it was created via UI, REST, or import.

Where it is

packages/server/src/services/generation/tool-resolution-runtime.ts: the throwing branch in validateToolSchema at lines 249-251, and the silent loadToolDefinitions catch at lines 329-337. The default originates at packages/shared/src/schemas/custom-tool.schema.ts:15 (parametersSchema: z.record(z.unknown()).default({})) and is persisted unnormalized at packages/server/src/services/storage/custom-tools.storage.ts:42. The contrasting UI emitter is packages/client/src/components/agents/ToolEditor.tsx:140-149.

What's happening

validateToolSchema treats a schema with no type and no properties as invalid, but the persisted default for a parameter-less custom tool is exactly {}. The create route accepts {} without normalizing it to { type: "object", properties: {} }, so the empty object survives to generation time where it is rejected and the tool dropped.

Suggested fix

In tool-resolution-runtime.ts, replace the throwing branch in validateToolSchema (lines 249-251) with in-place normalization so a parameter-less tool is treated as a zero-parameter object schema:

// A schema with neither root "type" nor "properties" is the legitimate
// "tool takes no parameters" case (the persisted default is `{}`). Normalize
// it to a valid zero-parameter object schema instead of dropping the tool.
if (schemaType === undefined) {
  schemaObject.type = "object";
}
if (schemaProperties === undefined) {
  schemaObject.properties = {};
}

Leave the rest of the function unchanged so the earlier guards and the trailing required check still run and the now-normalized schemaObject is returned. This single generation-time fix covers newly-created REST tools, already-stored {} rows, imported packages lacking a schema, and the Zod/DB {} default in one place, matching the canonical { type: "object", properties: {} } shape the UI and built-in tools already emit.

Regression avoided: the fix normalizes the missing type/properties keys in place and falls through to the existing required check rather than early-returning a fresh {type:"object",properties:{}} object — so it neither skips the required validation nor discards other already-present valid keys (e.g. a schema carrying {required:[...]} but no type). The alternative "normalize at create/update time" was rejected as incomplete: it would not fix rows already persisted with {}.

Related: this touches the same validateToolSchema function as the nested-property-validation gap (filed as a sibling issue). Coordinate the two — this one relaxes the empty-{} case; the other adds nested validation.


AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.

Originally created by @kolacheee on GitHub (Jun 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3007 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** `validateToolSchema` rejects a schema that has neither a root `type` nor `properties`. The Zod schema for custom tools defaults `parametersSchema` to `{}` when the field is omitted. A custom tool stored with `parametersSchema = {}` therefore fails validation in `loadToolDefinitions`, is caught, logged only as a server `warn`, and silently skipped — so the tool never reaches the model even though it shows as enabled. This is the legitimate "tool takes no parameters" case, which the client UI handles fine (it emits `{ type: "object", properties: {}, required: [] }`). The result is an inconsistency: a no-parameter tool created in the UI works, but the same tool created via the REST API (omitting `parametersSchema`) or imported from a package lacking a schema is silently non-functional. **How to reproduce (try it yourself)** 1. `POST /custom-tools` with a body that omits `parametersSchema`, e.g. `{ "name": "get_time", "description": "...", "executionType": "static", "staticResult": "now" }`. Zod applies `.default({})` and the tool is stored with `parametersSchema = "{}"`. (Or import a tool package whose source has no/invalid parametersSchema.) 2. Start a generation with tools enabled (`enableTools=true`). 3. Have the model attempt to call the tool. You'll see: `validateToolSchema({})` throws, the catch block deletes the registration and logs a `warn`, and the tool is omitted from the definitions sent to the model. The model never sees the tool and there is no user-facing error. Expected: a zero-parameter custom tool is offered to the model regardless of whether it was created via UI, REST, or import. **Where it is** `packages/server/src/services/generation/tool-resolution-runtime.ts`: the throwing branch in `validateToolSchema` at lines 249-251, and the silent `loadToolDefinitions` catch at lines 329-337. The default originates at `packages/shared/src/schemas/custom-tool.schema.ts:15` (`parametersSchema: z.record(z.unknown()).default({})`) and is persisted unnormalized at `packages/server/src/services/storage/custom-tools.storage.ts:42`. The contrasting UI emitter is `packages/client/src/components/agents/ToolEditor.tsx:140-149`. **What's happening** `validateToolSchema` treats a schema with no `type` and no `properties` as invalid, but the persisted default for a parameter-less custom tool is exactly `{}`. The create route accepts `{}` without normalizing it to `{ type: "object", properties: {} }`, so the empty object survives to generation time where it is rejected and the tool dropped. **Suggested fix** In `tool-resolution-runtime.ts`, replace the throwing branch in `validateToolSchema` (lines 249-251) with in-place normalization so a parameter-less tool is treated as a zero-parameter object schema: ```ts // A schema with neither root "type" nor "properties" is the legitimate // "tool takes no parameters" case (the persisted default is `{}`). Normalize // it to a valid zero-parameter object schema instead of dropping the tool. if (schemaType === undefined) { schemaObject.type = "object"; } if (schemaProperties === undefined) { schemaObject.properties = {}; } ``` Leave the rest of the function unchanged so the earlier guards and the trailing `required` check still run and the now-normalized `schemaObject` is returned. This single generation-time fix covers newly-created REST tools, already-stored `{}` rows, imported packages lacking a schema, and the Zod/DB `{}` default in one place, matching the canonical `{ type: "object", properties: {} }` shape the UI and built-in tools already emit. *Regression avoided:* the fix normalizes the missing `type`/`properties` keys in place and falls through to the existing `required` check rather than early-returning a fresh `{type:"object",properties:{}}` object — so it neither skips the `required` validation nor discards other already-present valid keys (e.g. a schema carrying `{required:[...]}` but no `type`). The alternative "normalize at create/update time" was rejected as incomplete: it would not fix rows already persisted with `{}`. *Related: this touches the same `validateToolSchema` function as the nested-property-validation gap (filed as a sibling issue). Coordinate the two — this one relaxes the empty-`{}` case; the other adds nested validation.* --- *AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.*
Author
Owner

@SpicyMarinara commented on GitHub (Jun 29, 2026):

Fixed in merged staging PR #3018.

<!-- gh-comment-id:4833016612 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed in merged staging PR #3018.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#1579
No description provided.