Skip to content

fix(workflows): give freeform JSON tool params a concrete JSON-Schema type - #3836

Closed
leduckhc wants to merge 1 commit into
get-bb:mainfrom
leduckhc:fix/workflows-typed-freeform-json
Closed

leduckhc wants to merge 1 commit into
get-bb:mainfrom
leduckhc:fix/workflows-typed-freeform-json

Conversation

@leduckhc

Copy link
Copy Markdown

Human comments

What was wrong

The builtin Workflows plugin registered the bb_workflow_run.args and bb_workflow_result.value tool parameters with z.unknown(), which serialises to a JSON-Schema node carrying only description + default and no type keyword. Strict provider validators (Azure OpenAI / Kimi K2.7) reject that typeless node with invalid_request_error: "could not understand the instance" before the model runs, blocking any turn that exposes those tools on such providers. Lenient validators (GLM 5.2) accept the same node, so the failure is provider-specific.

Issue: #3835.

What changed

plugins/workflows/src/server.ts — replaced const freeformJson = z.unknown() with a non-recursive union of the JSON scalar/container types (string | number | boolean | null | array<unknown> | record<string, unknown>). Every anyOf branch now carries a concrete type, while the schema still accepts any JSON value (the set accepted is exactly what toJsonValue in json-value.ts validates). The union is deliberately non-recursive (no $ref/$defs) so providers that reject recursive schemas still accept it — consistent with the existing registers tool schemas without recursive $refs test.

Emitted schema for the args node (with .describe().default(null)):

{"default":null,"anyOf":[{"type":"string"},{"type":"number"},{"type":"boolean"},{"type":"null"},{"type":"array","items":{}},{"type":"object","propertyNames":{"type":"string"},"additionalProperties":{}}],"description":"..."}

No wire/protocol/CLI changes.

How you verified

  • New regression test in server-harness.test.ts: "registers typed freeform JSON parameter schemas (no typeless top-level nodes)" — asserts the args and value nodes declare a concrete type or anyOf and are not a bare $ref. This fails on the old z.unknown() (node has neither type nor anyOf) and passes after the fix.
  • Existing registers tool schemas without recursive $refs test still passes (no $ref/$defs introduced).
  • pnpm vitest run for the workflows plugin: 241 tests across 14 files pass.
  • Manually confirmed the emitted JSON Schema has a top-level anyOf with typed branches and no $ref/$defs.

Note: I am not on .github/APPROVED_CONTRIBUTORS; happy to go through the approval flow (Discord #contributors or /approve @leduckhc). The fork branch is linked from the issue as a prototype.

Fixes #3835

AGENT GENERATED

… type

bb_workflow_run.args and bb_workflow_result.value were declared with
z.unknown(), which serialises to a JSON-Schema node carrying only
description + default and no `type`. Strict provider validators
(Azure OpenAI / Kimi K2.7) reject that node with
"could not understand the instance" before the model runs.

Replace z.unknown() with a non-recursive union of the JSON
scalar/container types so every anyOf branch has a concrete `type`,
while still accepting any JSON value (matching toJsonValue). Stays
non-recursive (no $ref/$defs) so providers that reject recursive
schemas still accept it.

Adds a regression test asserting args/value declare a concrete type or
anyOf. Existing "registers tool schemas without recursive $refs" test
and all 241 workflows tests still pass.

Fixes get-bb#3835
@github-actions

Copy link
Copy Markdown
Contributor

Thanks @leduckhc for the PR. This repo needs approval before a PR. Join the #contributors channel in Discord (https://discord.gg/kvBU6tJhcJ) and explain what you want to open a PR for and why. A maintainer then adds you to the allow list. This PR now closes on its own. Reopen it or open a new one after approval.

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.

Workflows tool params use typeless JSON-Schema (z.unknown()), rejected by strict validators (Kimi K2.7/Azure)

1 participant