Handle incomplete function call arguments from interrupted LLM streams

When a user interruption causes the LLM chunk stream to exit early,
function call arguments may be incomplete JSON. Wrap json.loads() in
try/except JSONDecodeError to skip malformed function calls with a
warning instead of crashing. Fixes #2461.
This commit is contained in:
Mark Backman
2026-03-30 14:24:04 -04:00
parent 87b8f38a48
commit 4adf0fd585
3 changed files with 15 additions and 3 deletions

View File

@@ -199,7 +199,11 @@ class GoogleLLMOpenAIBetaService(OpenAILLMService):
# which currently results in an empty function name('').
continue
arguments = json.loads(arguments)
try:
arguments = json.loads(arguments)
except json.JSONDecodeError:
logger.warning(f"{self}: Failed to parse function call arguments: {arguments}")
continue
function_calls.append(
FunctionCallFromLLM(

View File

@@ -567,7 +567,11 @@ class BaseOpenAILLMService(LLMService):
for function_name, arguments, tool_id in zip(
functions_list, arguments_list, tool_id_list
):
arguments = json.loads(arguments)
try:
arguments = json.loads(arguments)
except json.JSONDecodeError:
logger.warning(f"{self}: Failed to parse function call arguments: {arguments}")
continue
function_calls.append(
FunctionCallFromLLM(
context=context,

View File

@@ -245,7 +245,11 @@ class SambaNovaLLMService(OpenAILLMService): # type: ignore
if len(arguments) < 1:
continue
arguments = json.loads(arguments)
try:
arguments = json.loads(arguments)
except json.JSONDecodeError:
logger.warning(f"{self}: Failed to parse function call arguments: {arguments}")
continue
function_calls.append(
FunctionCallFromLLM(
context=context,