Skip to content

Commit 9215c7c

Browse files
replicas-connector[bot]claudeH2Shami
committed
fix: add strict mode support for OpenAI tool definitions in prompt-2025 endpoint
Users were receiving a 422 Unprocessable Entity error when creating prompts with tool definitions that include OpenAI's strict mode (strict: true) and additionalProperties: false in the function parameters. Changes: - Add `strict` field to OpenAIChatRequest tools function interface - Make `description` and `parameters` optional in tool function definition to match OpenAI's API behavior - Update internal Tool type to include `strict` property - Update toExternalTools and convertTools functions to preserve the strict field - Update TSOA validation schemas in routes.ts to accept strict mode This allows prompts with tool calls using OpenAI's strict mode for function calling to be created and validated correctly. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Co-Authored-By: Hammad Shami <hammad@helicone.ai>
1 parent 1ab78af commit 9215c7c

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

packages/llm-mapper/mappers/openai/chat-v2.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ export interface OpenAIChatRequest {
3737
type: "function";
3838
function: {
3939
name: string;
40-
description: string;
41-
parameters: Record<string, any>; // JSON Schema
40+
description?: string;
41+
parameters?: Record<string, any>; // JSON Schema
42+
strict?: boolean;
4243
};
4344
}[];
4445
tool_choice?:
@@ -294,7 +295,8 @@ const toExternalTools = (
294295
function: {
295296
name: tool.name,
296297
description: tool.description,
297-
parameters: tool.parameters || {},
298+
parameters: tool.parameters,
299+
strict: tool.strict,
298300
},
299301
}));
300302
};
@@ -311,6 +313,7 @@ const convertTools = (
311313
name: tool.function?.name,
312314
description: tool.function?.description,
313315
parameters: tool.function?.parameters,
316+
strict: tool.function?.strict,
314317
}));
315318
};
316319

packages/llm-mapper/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,9 @@ export type Response = {
225225
/* -------------------------------------------------------------------------- */
226226
export interface Tool {
227227
name: string;
228-
description: string;
228+
description?: string;
229229
parameters?: Record<string, any>; // Strict JSON Schema type ("parameters" in OPENAI, "input_schema" in ANTHROPIC)
230+
strict?: boolean; // OpenAI's strict mode for function calling
230231
}
231232
export interface FunctionCall {
232233
id?: string;

valhalla/jawn/src/tsoa-build/private/routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ const models: TsoaRoute.Models = {
931931
"max_completion_tokens": {"dataType":"double"},
932932
"stream": {"dataType":"boolean"},
933933
"stop": {"dataType":"union","subSchemas":[{"dataType":"array","array":{"dataType":"string"}},{"dataType":"string"}]},
934-
"tools": {"dataType":"array","array":{"dataType":"nestedObjectLiteral","nestedProperties":{"function":{"dataType":"nestedObjectLiteral","nestedProperties":{"parameters":{"ref":"Record_string.any_","required":true},"description":{"dataType":"string","required":true},"name":{"dataType":"string","required":true}},"required":true},"type":{"dataType":"enum","enums":["function"],"required":true}}}},
934+
"tools": {"dataType":"array","array":{"dataType":"nestedObjectLiteral","nestedProperties":{"function":{"dataType":"nestedObjectLiteral","nestedProperties":{"strict":{"dataType":"boolean"},"parameters":{"ref":"Record_string.any_"},"description":{"dataType":"string"},"name":{"dataType":"string","required":true}},"required":true},"type":{"dataType":"enum","enums":["function"],"required":true}}}},
935935
"tool_choice": {"dataType":"union","subSchemas":[{"dataType":"enum","enums":["none"]},{"dataType":"enum","enums":["auto"]},{"dataType":"enum","enums":["required"]},{"dataType":"nestedObjectLiteral","nestedProperties":{"function":{"dataType":"nestedObjectLiteral","nestedProperties":{"name":{"dataType":"string","required":true},"type":{"dataType":"enum","enums":["function"],"required":true}}},"type":{"dataType":"string","required":true}}}]},
936936
"parallel_tool_calls": {"dataType":"boolean"},
937937
"reasoning_effort": {"dataType":"union","subSchemas":[{"dataType":"enum","enums":["minimal"]},{"dataType":"enum","enums":["low"]},{"dataType":"enum","enums":["medium"]},{"dataType":"enum","enums":["high"]}]},

valhalla/jawn/src/tsoa-build/public/routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ const models: TsoaRoute.Models = {
496496
"max_completion_tokens": {"dataType":"double"},
497497
"stream": {"dataType":"boolean"},
498498
"stop": {"dataType":"union","subSchemas":[{"dataType":"array","array":{"dataType":"string"}},{"dataType":"string"}]},
499-
"tools": {"dataType":"array","array":{"dataType":"nestedObjectLiteral","nestedProperties":{"function":{"dataType":"nestedObjectLiteral","nestedProperties":{"parameters":{"ref":"Record_string.any_","required":true},"description":{"dataType":"string","required":true},"name":{"dataType":"string","required":true}},"required":true},"type":{"dataType":"enum","enums":["function"],"required":true}}}},
499+
"tools": {"dataType":"array","array":{"dataType":"nestedObjectLiteral","nestedProperties":{"function":{"dataType":"nestedObjectLiteral","nestedProperties":{"strict":{"dataType":"boolean"},"parameters":{"ref":"Record_string.any_"},"description":{"dataType":"string"},"name":{"dataType":"string","required":true}},"required":true},"type":{"dataType":"enum","enums":["function"],"required":true}}}},
500500
"tool_choice": {"dataType":"union","subSchemas":[{"dataType":"enum","enums":["none"]},{"dataType":"enum","enums":["auto"]},{"dataType":"enum","enums":["required"]},{"dataType":"nestedObjectLiteral","nestedProperties":{"function":{"dataType":"nestedObjectLiteral","nestedProperties":{"name":{"dataType":"string","required":true},"type":{"dataType":"enum","enums":["function"],"required":true}}},"type":{"dataType":"string","required":true}}}]},
501501
"parallel_tool_calls": {"dataType":"boolean"},
502502
"reasoning_effort": {"dataType":"union","subSchemas":[{"dataType":"enum","enums":["minimal"]},{"dataType":"enum","enums":["low"]},{"dataType":"enum","enums":["medium"]},{"dataType":"enum","enums":["high"]}]},

0 commit comments

Comments
 (0)