Back to Issue home

permission error

#permission-error

Sorted by views, then solution_desc, solution, and root_cause length (desc).

2601 issues

openai: malformed tool calls cause all tool calls to be silently dropped

**What I'm doing:** Processing streaming chat responses that include tool calls from OpenAI-compatible APIs. **Expected behavior:** When one tool call in a batch is malformed (missing required 'function' key), the valid tool calls should still be processed. The malformed one should be skipped or logged, but valid tool calls should not be lost. **Actual behavior:** A bare `except KeyError: pass` in `_convert_delta_to_message_chunk` causes the entire list comprehension to fail, silently dropping ALL tool calls when ANY single tool call is malformed. **Root Cause:** In `libs/partners/openai/langchain_openai/chat_models/base.py`, lines 417-429: ```python if raw_tool_calls := _dict.get("tool_calls"): try: tool_call_chunks = [ tool_call_chunk( name=rtc["function"].get("name"), args=rtc["function"].get("arguments"), id=rtc.get("id"), index=rtc["index"], ) for rtc in raw_tool_calls ] except KeyError: pass # BUG: This silently drops ALL tool calls ``` The `except KeyError: pass` wraps the entire list comprehension. When any single tool call lacks the 'function' or 'index' keys, the entire batch is discarded without warning. **Impact:** - Silent data loss in streaming responses - Difficult to debug since no error is raised - Affects all OpenAI-compatible integrations **Suggested Fix:** Handle errors per-tool-call rather than for the entire batch: ```python tool_call_chunks = [] for rtc in raw_tool_calls: try: tool_call_chunks.append( tool_call_chunk( name=rtc["function"].get("name"), args=rtc["function"].get("arguments"), id=rtc.get("id"), index=rtc["index"], ) ) except KeyError: # Log warning or skip silently per-tool-call continue ``` **I am willing to submit a PR to fix this issue.** Please assign this issue to me. I have already identified the root cause and can implement the fix as suggested above.