Skip to content

Commit 5fd1dbd

Browse files
authored
[codex] Clarify string tool input errors (#599)
1 parent 4c765b3 commit 5fd1dbd

2 files changed

Lines changed: 45 additions & 6 deletions

File tree

packages/agent-runtime/src/__tests__/tool-validation-error.test.ts

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,46 @@ describe('tool validation error handling', () => {
239239

240240
expect('error' in result).toBe(true)
241241
if ('error' in result) {
242-
expect(result.error).toContain('The JSON parser reported:')
243-
expect(result.error).toContain('If the arguments are incomplete')
242+
expect(result.error).toContain(
243+
'expected the tool arguments to be an object, but received a string',
244+
)
245+
expect(result.error).toContain('Parsing as JSON failed:')
246+
expect(result.error).toContain(
247+
'The arguments may be malformed or incomplete',
248+
)
249+
}
250+
})
251+
252+
it('should explain when parsed tool input remains a string', () => {
253+
const input = JSON.stringify(
254+
JSON.stringify(
255+
JSON.stringify(
256+
JSON.stringify({
257+
path: 'test.ts',
258+
instructions: 'Writes a test file',
259+
content: 'console.log("test")\n',
260+
}),
261+
),
262+
),
263+
)
264+
265+
const result = parseRawToolCall({
266+
rawToolCall: {
267+
toolName: 'write_file',
268+
toolCallId: 'over-encoded-tool-call-id',
269+
input,
270+
},
271+
})
272+
273+
expect('error' in result).toBe(true)
274+
if ('error' in result) {
275+
expect(result.error).toContain(
276+
'expected the tool arguments to be an object, but received a string',
277+
)
278+
expect(result.error).toContain(
279+
'Parsing succeeded, but the parsed value was still a string',
280+
)
281+
expect(result.error).not.toContain('malformed or incomplete')
244282
}
245283
})
246284

@@ -578,8 +616,9 @@ describe('tool validation error handling', () => {
578616
)
579617
expect(errorEvents.length).toBe(1)
580618
expect(errorEvents[0].message).toContain(
581-
'tool arguments were a string, not a JSON object',
619+
'expected the tool arguments to be an object, but received a string',
582620
)
621+
expect(errorEvents[0].message).toContain('Parsing as JSON failed:')
583622
expect(errorEvents[0].message).toContain('Original tool call input:')
584623

585624
expect(result.hadToolCallError).toBe(true)

packages/agent-runtime/src/tools/tool-executor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,13 @@ function stringInputError(
130130
parseError?: string,
131131
): ToolCallError {
132132
const parseDetails = parseError
133-
? ` The JSON parser reported: ${parseError}. If the arguments are incomplete, re-issue the full object.`
134-
: ''
133+
? ` Parsing as JSON failed: ${parseError}. The arguments may be malformed or incomplete.`
134+
: ' Parsing succeeded, but the parsed value was still a string.'
135135
return {
136136
toolName,
137137
toolCallId,
138138
input: {},
139-
error: `Invalid parameters for ${toolName}: tool arguments were a string, not a JSON object. The runtime tried to parse stringified JSON before validation, but the value was still not a JSON object.${parseDetails} Re-issue the tool call as a JSON object with properly escaped string values.`,
139+
error: `Invalid parameters for ${toolName}: expected the tool arguments to be an object, but received a string.${parseDetails} Re-issue the tool call with the full arguments object and properly escaped string values.`,
140140
}
141141
}
142142

0 commit comments

Comments
 (0)