I tried to switch a PoC chat built with Ash AI from OpenAI to Google models (Gemini), and tool use broke because of the presence of additionalProperties
in the JSON
It looks like in pydantic-ai they suffered a similar problem pydantic-ai Gemini Schema Generation Fails for Dynamically Created Models with List[KeyValuePair] Replacement for Dict · Issue #1469 · pydantic/pydantic-ai · GitHub
Here is a simple live tool use test with Gemini that generates the error Added a failing that fails in a live call to the Google API because of · ash-project/ash_ai@47321f3 · GitHub (generated), the error looks like:
$ mix test test/ash_ai/gemini_additional_properties_test.exs --include live_call --include live_google_ai
Running ExUnit with seed: 401571, max_cases: 16
Including tags: [:live_call, :live_google_ai]
21:30:23.677 [error] Error during chat call. Reason: %LangChain.LangChainError{type: nil, message: "Failed with status: 400", original: %Req.Response{status: 400, headers: %{"alt-svc" => ["h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000"], "content-type" => ["application/json; charset=UTF-8"], "date" => ["Mon, 23 Jun 2025 02:30:23 GMT"], "server" => ["scaffolding on HTTPServer2"], "server-timing" => ["gfet4t7; dur=415"], "transfer-encoding" => ["chunked"], "vary" => ["Origin", "X-Origin", "Referer"], "x-content-type-options" => ["nosniff"], "x-frame-options" => ["SAMEORIGIN"], "x-xss-protection" => ["0"]}, body: %{"error" => %{"code" => 400, "details" => [%{"@type" => "type.googleapis.com/google.rpc.BadRequest", "fieldViolations" => [%{"description" => "Invalid JSON payload received. Unknown name \"additionalProperties\" at 'tools[0].function_declarations[0].parameters': Cannot find field.", "field" => "tools[0].function_declarations[0].parameters"}]}], "message" => "Invalid JSON payload received. Unknown name \"additionalProperties\" at 'tools[0].function_declarations[0].parameters': Cannot find field.", "status" => "INVALID_ARGUMENT"}}, trailers: %{}, private: %{}}}
This patch (generated) Tool use is working with a live call to the Google/Gemini API · ash-project/ash_ai@89ddbd6 · GitHub fixes the error.
Not opening a PR because I am just starting to learn Elixir and I can’t really evaluate the quality of the code, despite it not being particularly complex.
Also, bumped into a different error later in the PoC app that looks related to handling a streamed response from Google, but I still need to confirm it with an isolated failing test.