fix(llms): add error handling for invalid JSON responses and schema validation

This commit is contained in:
Simon
2026-06-03 23:14:12 +08:00
parent fd12fb9f1b
commit 823195ad94
2 changed files with 16 additions and 3 deletions

View File

@@ -10,6 +10,8 @@ export const InvokeErrorTypes = {
NO_TOOL_CALL: 'no_tool_call', // Model did not call tool
INVALID_TOOL_ARGS: 'invalid_tool_args', // Tool args don't match schema
TOOL_EXECUTION_ERROR: 'tool_execution_error', // Tool execution error
INVALID_RESPONSE: 'invalid_response', // Response body is not valid JSON
INVALID_SCHEMA: 'invalid_schema', // Response is valid JSON but doesn't match expected shape
UNKNOWN: 'unknown',
@@ -29,6 +31,8 @@ const RETRYABLE_TYPES: readonly InvokeErrorType[] = [
InvokeErrorTypes.NO_TOOL_CALL,
InvokeErrorTypes.INVALID_TOOL_ARGS,
InvokeErrorTypes.TOOL_EXECUTION_ERROR,
InvokeErrorTypes.INVALID_RESPONSE,
InvokeErrorTypes.INVALID_SCHEMA,
InvokeErrorTypes.UNKNOWN,
]