Skip to content

fix(tools): preserve the strict flag when converting tool definitions - #138

Merged
veerareddyvishal144 merged 1 commit into
Fast-Editor:mainfrom
officialasishkumar:fix/preserve-tool-strict-flag
Nov 15, 2026
Merged

veerareddyvishal144 merged 1 commit into
Fast-Editor:mainfrom
officialasishkumar:fix/preserve-tool-strict-flag

Conversation

@officialasishkumar

Copy link
Copy Markdown
Contributor

Refs #116

Follow-up to the remaining part of #116 (see the comment from 24 Sep): the schema compressor was fixed, but three other tool rebuilds still drop strict, so a strict tool arrives upstream as non-strict.

  • convertOpenAIToAnthropic (src/clients/openai-format.js)
  • ensureAnthropicToolFormat (src/orchestrator/index.js), both for OpenAI-shaped and Anthropic-shaped tools
  • convertAnthropicToolsToOpenRouter (src/clients/openrouter-utils.js)

A boolean strict is now carried through each; it is omitted when the client did not set it, so existing payloads are unchanged.

Tests: new test/tool-strict-preservation.test.js (added to test:unit) covers each converter plus an OpenAI Chat round trip. 4 of its 6 tests fail without the change. Ran it together with the format-conversion, schema-compression, ingress and azure format tests: 65 pass, 0 fail.

Three tool rebuilds dropped the `strict` flag, so a strict-schema tool
sent by a client reached the upstream as a non-strict tool:

- convertOpenAIToAnthropic (OpenAI Chat -> Anthropic) built tools from
  name/description/parameters only.
- ensureAnthropicToolFormat (orchestrator) did the same when unwrapping
  OpenAI-shaped tools and when normalising Anthropic ones.
- convertAnthropicToolsToOpenRouter (Anthropic -> OpenAI-format upstreams)
  never emitted function.strict.

Each now carries a boolean strict through, and omits it when the client
did not set one. Adds regression tests, including a full OpenAI Chat
round trip, and registers them in test:unit.

Refs Fast-Editor#116
@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

🔍 OpenCodeReview found 3 issue(s) in this PR.

  • ✅ Successfully posted inline: 3 comment(s)

}
};
// Keep the strict-schema flag so it survives the round trip.
if (typeof tool.function.strict === "boolean") converted.strict = tool.function.strict;

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.

maintainability · medium
The condition typeof tool.function.strict === "boolean" does not protect against a null/undefined tool.function in case the earlier .filter logic changes or tool structure varies. Accessing tool.function.strict directly risks a TypeError if tool.function is missing.

Suggestion:

Suggested change
if (typeof tool.function.strict === "boolean") converted.strict = tool.function.strict;
if (tool.function && typeof tool.function.strict === "boolean") converted.strict = tool.function.strict;

Comment on lines +35 to 43
const fn = {
name: tool.name,
description: tool.description || "",
parameters: tool.input_schema || {
type: "object",
properties: {},
required: []
}
};

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.

maintainability · low
Similar to the previous file, tool.strict is accessed without ensuring tool itself is valid (though unlikely given the earlier checks). More importantly, the new fn object construction duplicates the schema fallback logic (type: 'object', properties: {}, required: []) already present in openai-format.js. Consider extracting this schema fallback into a shared utility for consistency.

Comment thread src/orchestrator/index.js
name: tool.function.name,
description: tool.function.description,
input_schema: tool.function.parameters,
...(typeof tool.function.strict === "boolean" ? { strict: tool.function.strict } : {}),

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.

maintainability · low
The spread operator with a conditional ternary for including strict adds unnecessary verbosity. A simpler approach would be to check the type once and assign directly, or use a helper function if this pattern repeats elsewhere in the codebase.

@veerareddyvishal144
veerareddyvishal144 merged commit ab2e458 into Fast-Editor:main Nov 15, 2026
2 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