Skip to content

Tool calls fail with 400 Bad Request due to strict JSON Schema violations (OpenAI) #1265

Closed

Description

@svetanis

Tool calls fail with 400 Bad Request due to strict JSON Schema violations (OpenAI)

The ADK framework's ChatCompletionsRequest serialization generates JSON payloads that violate strict OpenAI/Groq requirements. Specifically, it maps empty arguments maps and empty function response objects to null or omits them entirely, which causes the downstream API to drop the context and hallucinate.

Please make sure you read the contribution guide and file the issues in the right place.
Contribution guide.

🔴 Required Information

Describe the Bug:
When using third-party OpenAI-compatible providers like Groq, multi-turn tool calling fails. If an agent executes a tool that requires 0 arguments (like getCurrentTime), the ADK serializes the assistant's message with arguments: null or omits the arguments field. Furthermore, during tool declaration, it omits the parameters schema object entirely for zero-argument functions. Strict parsers (like Groq) reject or silently drop this malformed tool history, leading the model to lose context. Consequently, the model hallucinates raw XML-like tool calls, causing a fatal 400 Bad Request error. Additionally, JSON Schema enum types for tools are incorrectly serialized in uppercase (e.g., "STRING" instead of "string").

Steps to Reproduce:

  1. Configure an ADK agent with multiple tools (e.g., getCurrentTime, getWeather).
  2. Set the model provider to groq/llama-3.3-70b-versatile.
  3. Send a prompt that requires executing a tool with no arguments.
  4. The first tool executes, but the subsequent request to the model crashes with a 400 Bad Request.

Expected Behavior:
The ADK ChatCompletionsRequest should strictly comply with the OpenAI JSON specifications:

  • arguments must be a non-null JSON string (e.g., "{}" if empty).
  • content for tool roles must be a non-null string (e.g., "{}" if empty).
  • parameters schema objects must exist in function declarations, even for zero-argument functions (e.g., {"type":"object", "properties":{}}).
  • JSON Schema Type enums must be serialized in lowercase.

Observed Behavior:
The framework throws a 400 Bad Request exception due to model hallucinations caused by dropped context:

Exception in thread "main" java.lang.RuntimeException: java.io.IOException: HTTP request failed with status: Response{protocol=h2, code=400, message=, url=https://api.groq.com/openai/v1/chat/completions} - body: {"error":{"message":"tool call validation failed: attempted to call tool 'brave_search' which was not in request.tools","type":"invalid_request_error","code":"tool_use_failed","failed_generation":"<function=brave_search>{\"query\":\"HACK stock price\"}</function>"}}

Environment Details:

  • ADK Library Version: 1.4.1-SNAPSHOT
  • OS: Windows (also reproducible on macOS/Linux)
  • TS Version: N/A

Model Information:

  • Which model is being used: groq/llama-3.3-70b-versatile

🟡 Optional Information

How often has this issue occurred?:

  • Always (100%)

Activity

  1. self-assigned this
    on Jun 15, 2026
  2. added theissue type on Jun 15, 2026
  3. hemasekhar-p commented on Jun 15, 2026

    @hemasekhar-p
    Contributor

    Hi @svetanis, Thanks for reporting this issue and and We appreciate you taking the time to submit this pull request. I have added the Comments in the PR, could you please address them?

  4. added
    waiting on reporterWaiting for reaction by reporter. Failing that, maintainers will eventually closed it as stale.
    on Jun 15, 2026
  5. svetanis commented on Jun 16, 2026

    @svetanis
    ContributorAuthor

    Hi @hemasekhar-p ,

    Thank you for looking into this! I have just pushed an update to the PR addressing your comments. I've added the missing unit tests to verify the JSON Schema compliance, and I've also rebased the branch to resolve conflicts with the latest main.

    Let me know if everything looks good on the PR side!

  6. hemasekhar-p commented on Jun 16, 2026

    @hemasekhar-p
    Contributor

    @svetanis, Thank you for addressing the comments. Currently this Issue and PR are under review by our team, we will keep you update if any additional information is required. thank you.

  7. hemasekhar-p commented on Jun 16, 2026

    @hemasekhar-p
    Contributor

    @anFatum, Please have a look into it.

  8. added and removed
    waiting on reporterWaiting for reaction by reporter. Failing that, maintainers will eventually closed it as stale.
    on Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions