Skip to content

Commit dfa37ff

Browse files
replicas-connector[bot]claudeH2Shami
authored
fix: add strict mode support for OpenAI tool definitions in prompt-2025 endpoint (#5538)
* 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> * fix: handle optional description in tool conversion functions Fix TypeScript compilation errors by providing default empty string when tool.description is undefined in toExternalTools functions for Anthropic and OpenAI responses mappers. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * auto generated file commit * Revert "fix: handle optional description in tool conversion functions" This reverts commit 00ce337. The nullish coalescing changes were not necessary - the actual fix was regenerating the TSOA routes files to pick up the updated type definitions. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: handle optional description in tool conversion functions Since the Tool interface's description field is now optional (string | undefined), the toExternalTools functions need to provide a default empty string when converting to external API types that expect a required string field. This fixes TypeScript compilation errors in anthropic/chat-v2.ts and openai/responses.ts mappers. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: replicas-connector[bot] <replicas-connector[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Hammad Shami <hammad@helicone.ai>
1 parent 7e146fa commit dfa37ff

File tree

14 files changed

+62
-37
lines changed

14 files changed

+62
-37
lines changed

bifrost/lib/clients/jawnTypes/private.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,8 +1621,9 @@ Json: JsonObject;
16211621
stop?: string[] | string;
16221622
tools?: {
16231623
function: {
1624-
parameters: components["schemas"]["Record_string.any_"];
1625-
description: string;
1624+
strict?: boolean;
1625+
parameters?: components["schemas"]["Record_string.any_"];
1626+
description?: string;
16261627
name: string;
16271628
};
16281629
/** @enum {string} */
@@ -2041,8 +2042,9 @@ Json: JsonObject;
20412042
};
20422043
Tool: {
20432044
name: string;
2044-
description: string;
2045+
description?: string;
20452046
parameters?: components["schemas"]["Record_string.any_"];
2047+
strict?: boolean;
20462048
};
20472049
HeliconeEventTool: {
20482050
/** @enum {string} */

bifrost/lib/clients/jawnTypes/public.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,8 +1189,9 @@ export interface components {
11891189
stop?: string[] | string;
11901190
tools?: {
11911191
function: {
1192-
parameters: components["schemas"]["Record_string.any_"];
1193-
description: string;
1192+
strict?: boolean;
1193+
parameters?: components["schemas"]["Record_string.any_"];
1194+
description?: string;
11941195
name: string;
11951196
};
11961197
/** @enum {string} */
@@ -2117,8 +2118,9 @@ Json: JsonObject;
21172118
};
21182119
Tool: {
21192120
name: string;
2120-
description: string;
2121+
description?: string;
21212122
parameters?: components["schemas"]["Record_string.any_"];
2123+
strict?: boolean;
21222124
};
21232125
HeliconeEventTool: {
21242126
/** @enum {string} */

docs/swagger.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,9 @@
13461346
"properties": {
13471347
"function": {
13481348
"properties": {
1349+
"strict": {
1350+
"type": "boolean"
1351+
},
13491352
"parameters": {
13501353
"$ref": "#/components/schemas/Record_string.any_"
13511354
},
@@ -1357,8 +1360,6 @@
13571360
}
13581361
},
13591362
"required": [
1360-
"parameters",
1361-
"description",
13621363
"name"
13631364
],
13641365
"type": "object"
@@ -4893,11 +4894,13 @@
48934894
},
48944895
"parameters": {
48954896
"$ref": "#/components/schemas/Record_string.any_"
4897+
},
4898+
"strict": {
4899+
"type": "boolean"
48964900
}
48974901
},
48984902
"required": [
4899-
"name",
4900-
"description"
4903+
"name"
49014904
],
49024905
"type": "object",
49034906
"additionalProperties": false

helicone-mcp/src/types/public.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,8 +1189,9 @@ export interface components {
11891189
stop?: string[] | string;
11901190
tools?: {
11911191
function: {
1192-
parameters: components["schemas"]["Record_string.any_"];
1193-
description: string;
1192+
strict?: boolean;
1193+
parameters?: components["schemas"]["Record_string.any_"];
1194+
description?: string;
11941195
name: string;
11951196
};
11961197
/** @enum {string} */
@@ -2117,8 +2118,9 @@ Json: JsonObject;
21172118
};
21182119
Tool: {
21192120
name: string;
2120-
description: string;
2121+
description?: string;
21212122
parameters?: components["schemas"]["Record_string.any_"];
2123+
strict?: boolean;
21222124
};
21232125
HeliconeEventTool: {
21242126
/** @enum {string} */

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ const toExternalTools = (
189189

190190
return tools.map((tool) => ({
191191
name: tool.name,
192-
description: tool.description,
192+
description: tool.description ?? "",
193193
input_schema: tool.parameters || {},
194194
}));
195195
};

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/mappers/openai/responses.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ const toExternalTools = (
562562
type: "function",
563563
function: {
564564
name: tool?.name,
565-
description: tool?.description,
565+
description: tool?.description ?? "",
566566
parameters: tool?.parameters || {},
567567
},
568568
}));

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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ const models: TsoaRoute.Models = {
933933
"max_completion_tokens": {"dataType":"double"},
934934
"stream": {"dataType":"boolean"},
935935
"stop": {"dataType":"union","subSchemas":[{"dataType":"array","array":{"dataType":"string"}},{"dataType":"string"}]},
936-
"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}}}},
936+
"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}}}},
937937
"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}}}]},
938938
"parallel_tool_calls": {"dataType":"boolean"},
939939
"reasoning_effort": {"dataType":"union","subSchemas":[{"dataType":"enum","enums":["minimal"]},{"dataType":"enum","enums":["low"]},{"dataType":"enum","enums":["medium"]},{"dataType":"enum","enums":["high"]}]},
@@ -1256,8 +1256,9 @@ const models: TsoaRoute.Models = {
12561256
"dataType": "refObject",
12571257
"properties": {
12581258
"name": {"dataType":"string","required":true},
1259-
"description": {"dataType":"string","required":true},
1259+
"description": {"dataType":"string"},
12601260
"parameters": {"ref":"Record_string.any_"},
1261+
"strict": {"dataType":"boolean"},
12611262
},
12621263
"additionalProperties": false,
12631264
},

valhalla/jawn/src/tsoa-build/private/swagger.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3262,6 +3262,9 @@
32623262
"properties": {
32633263
"function": {
32643264
"properties": {
3265+
"strict": {
3266+
"type": "boolean"
3267+
},
32653268
"parameters": {
32663269
"$ref": "#/components/schemas/Record_string.any_"
32673270
},
@@ -3273,8 +3276,6 @@
32733276
}
32743277
},
32753278
"required": [
3276-
"parameters",
3277-
"description",
32783279
"name"
32793280
],
32803281
"type": "object"
@@ -4750,11 +4751,13 @@
47504751
},
47514752
"parameters": {
47524753
"$ref": "#/components/schemas/Record_string.any_"
4754+
},
4755+
"strict": {
4756+
"type": "boolean"
47534757
}
47544758
},
47554759
"required": [
4756-
"name",
4757-
"description"
4760+
"name"
47584761
],
47594762
"type": "object",
47604763
"additionalProperties": false

0 commit comments

Comments
 (0)