Ash AI not working

Failed to JSON decode error response. ERROR: %Jason.DecodeError{position: 1005, token: nil, data: "{\n \"error\": {\n \"code\": 400,\n \"message\": \"Invalid JSON payload received. Unknown name \\\"additionalProperties\\\" at 'tools[0].function_declarations[0].parameters
Failed to JSON decode error response. ERROR: %Jason.DecodeError{position: 1005, token: nil, data: "{\n \"error\": {\n \"code\": 400,\n \"message\": \"Invalid JSON payload received. Unknown name \\\"additionalProperties\\\" at 'tools[0].function_declarations[0].parameters
with this
action :search_varieties_tool, :string do
argument :query, :string do
allow_nil?(false)
public?(true)
end

run(fn ash_query, _context ->
search_query = ash_query.arguments.query
IO.inspect(search_query, label: "AI Tool Search Query")

case embedding_search(search_query) do
{:ok, varieties} ->
# Return simplified data structure for AI
simplified_varieties =
varieties
|> Enum.take(10)
|> Enum.map(fn variety ->
struct(variety, %{
processing: Enum.join(variety.processing || [], ", "),
variety: Enum.join(variety.variety || [], ", "),
description: String.slice(variety.description || "", 0, 200)
})
end)

{:ok, simplified_varieties}

{:error, _error} ->
{:ok, []}
end
end)
end
action :search_varieties_tool, :string do
argument :query, :string do
allow_nil?(false)
public?(true)
end

run(fn ash_query, _context ->
search_query = ash_query.arguments.query
IO.inspect(search_query, label: "AI Tool Search Query")

case embedding_search(search_query) do
{:ok, varieties} ->
# Return simplified data structure for AI
simplified_varieties =
varieties
|> Enum.take(10)
|> Enum.map(fn variety ->
struct(variety, %{
processing: Enum.join(variety.processing || [], ", "),
variety: Enum.join(variety.variety || [], ", "),
description: String.slice(variety.description || "", 0, 200)
})
end)

{:ok, simplified_varieties}

{:error, _error} ->
{:ok, []}
end
end)
end
4 Replies
theron
theronOP5d ago
Elixir Programming Language Forum
Ash AI tool use fails because of additionalProperties in JSON when ...
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 ...
theron
theronOP5d ago
Looks like this is a known issue? Should I create a GitHub ticket?
ZachDaniel
ZachDaniel5d ago
I think there may be one already
theron
theronOP4d ago
yes sir

Did you find this page helpful?