Skip to content

[Bug] validate_tool_calls() crashes with KeyError when LLM omits a required parameter #306

@sharma-sugurthi

Description

@sharma-sugurthi

What Operating System are you using (both controller, and any agents involved in the problem)?

Ubuntu Linux - reproducible on any OS since this is a pure python logic bug.

Reproduction steps

  1. start the chatbot with an LLM provider configured.
  2. send any user query that triggers the agentic retrieval pipeline (get_chatbot_reply_new_architecture or the _get_reply_simple_query_pipeline path).
  3. the LLM generates tool calls where a required parameter is missing - e.g: {"tool":"search_jenkins_docs", "params": {"keywords": "test"}} (missing the required query param).
  4. _get_agent_tool_calls() calls validate_tool_calls() to validate the parsed tool calls.
  5. validate_tool_calls() crashes with KeyError.

Expected Results

validate_tool_calls() should return False cleanly (without crashing) when a required parameter is missing from a tool call, allowing the caller (_get_agent_tool_calls) to fall back to default tool calls gracefully.

the warning message should correctly say "Param query is missing" (not "is not expected").

Actual Results

two bugs:

  1. KeyError crash : after line 87 confirms param_name not in params, the code falls through,which does params[param_name] - this raises KeyError because the param was just confirmed absent.

  2. Misleading warning message : the log says "Param %s is not expected" but the logic is checking the opposite - a required param is missing. The message should say "Param %s is missing".

Anything else?

the crash is currently masked in production because _get_agent_tool_calls() in chat_service.py catches KeyError as part of a broad except clause and silently falls back to default tool calls. however, this means:

  • the validation never returns a clean False - it always crashes
  • noisy tracebacks pollute logs on every LLM-generated tool call with a missing param
  • the misleading "is not expected" warning confuses debugging (it reads as if the param is extra, not absent)

Are you interested in contributing a fix?

yes, I would like to fix this. I will also add a corresponding unit test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions