fix(frontend): ensure type:object in test_run_flow tool schema for Anthropic (#9721)

Flows with no defined inputs can produce a sparse schema (e.g. { order: [] })
that lacks the "type": "object" field. buildSchemaForTool spread this schema
into the tool parameters as-is, so the Anthropic API rejected the tool
definition with `400 invalid_request_error:
tools.N.custom.input_schema.type: Field required`. The existing fallback in
anthropic.ts only triggers when parameters is falsy, but the sparse schema is
truthy.

Default type:object before spreading the schema in buildSchemaForTool, and
backfill type/properties/required in FlowAIChat's getFlowInputsSchema as a
defense-in-depth measure.

Fixes WIN-2087

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ruben Fiszel
2026-06-23 00:08:13 +02:00
committed by GitHub
parent e19594df2a
commit d5cb944cf9
2 changed files with 5 additions and 2 deletions
@@ -135,7 +135,8 @@
await acceptPendingFlowEditsIfEnabled()
},
getFlowInputsSchema: async () => {
return flowStore.val.schema ?? {}
const s = flowStore.val.schema ?? {}
return { type: 'object', properties: {}, required: [], ...s }
},
updateExprsToSet: (id: string, inputTransforms: Record<string, InputTransform>) => {
@@ -936,7 +936,9 @@ export async function buildSchemaForTool(
throw new Error(`Invalid flow inputs schema: ${invalidProperties.join(', ')}`)
}
toolDef.function.parameters = { ...schema, additionalProperties: false }
// Anthropic requires input_schema.type to be present; flows with no inputs
// can produce a sparse schema (e.g. { order: [] }) lacking it.
toolDef.function.parameters = { type: 'object', ...schema, additionalProperties: false }
// recursively normalize provider-incompatible schema fragments
normalizeToolParameterSchema(toolDef.function.parameters)