Skip to content

Conversation

@edlsh
Copy link

@edlsh edlsh commented Dec 7, 2025

Description

When an LLM calls a parameter-less tool, some providers return None or an empty string for the arguments field instead of valid JSON like "{}". This caused parse_tool_call to raise a TypeError because json.loads(None) is not valid.

Problem

raw_tool_call = {
    'function': {'arguments': None, 'name': 'orderStatus'},
    'id': 'chatcmpl-tool-8b1f759d874b412e931e64cf6f57bdcc',
    'type': 'function'
}
parse_tool_call(raw_tool_call, return_id=True)
# TypeError: the JSON object must be str, bytes or bytearray, not NoneType

Solution

Added a check to handle None and empty string arguments by treating them as an empty object {}, allowing parameter-less tools to be parsed correctly.

This is a minimal, targeted fix that:

  • Handles None arguments → returns {}
  • Handles empty string "" arguments → returns {}
  • Preserves existing behavior for valid JSON arguments
  • Preserves existing error handling for invalid JSON

Testing

Added 4 new unit tests:

  • test_parse_tool_call_with_none_arguments - reproduces the original bug
  • test_parse_tool_call_with_empty_string_arguments - handles empty strings
  • test_parse_tool_call_with_valid_arguments - ensures normal behavior works
  • test_parse_tool_call_partial_mode_with_none_arguments - verifies partial mode behavior

All existing tests continue to pass.


AI Disclosure: This PR was developed with assistance from Claude (AI).

Fixes #34123

When an LLM calls a parameter-less tool, some providers return None
for the arguments field instead of an empty string or "{}". This
caused parse_tool_call to raise a TypeError because json.loads(None)
is not valid.

This fix handles None and empty string arguments by treating them
as an empty object {}, allowing parameter-less tools to be parsed
correctly.

Fixes langchain-ai#34123
@edlsh edlsh requested a review from eyurtsev as a code owner December 7, 2025 18:43
@github-actions github-actions bot added fix core Related to the package `langchain-core` and removed fix labels Dec 7, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Dec 7, 2025

CodSpeed Performance Report

Merging #34242 will not alter performance

Comparing edlsh:fix/core-parse-tool-call-none-arguments (94287f4) with master (8a5f463)

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

Summary

✅ 13 untouched
⏩ 21 skipped1

Footnotes

  1. 21 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Related to the package `langchain-core`

Projects

None yet

Development

Successfully merging this pull request may close these issues.

openai_tools.parse_tool_call

1 participant