Merge pull request #4203 from pipecat-ai/mb/fix-json-decode-tool-calls

Handle incomplete function call arguments from interrupted LLM streams
This commit is contained in:
Mark Backman
2026-03-31 15:28:53 -04:00
committed by GitHub
4 changed files with 16 additions and 3 deletions

1
changelog/4203.fixed.md Normal file
View File

@@ -0,0 +1 @@
- Fixed a crash (`JSONDecodeError`) when a user interruption occurs while the LLM is streaming function call arguments. Previously, the incomplete JSON arguments were passed directly to `json.loads()`, causing an unhandled exception. Affected services: OpenAI, Google (OpenAI-compatible), and SambaNova.

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,