## TL;DR

Issue pydantic/pydantic-ai#631 (closed, 35 comments): I've been getting these sporadically when using Gemini: ``` Traceback (most recent call last): File "/workspaces/cardcraft/.venv/lib/python3.12/site-packages/pydantic_ai/agent.py", line 249, in run model_response, request_usage = await agent_model.request(messages, model_settings) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/workspaces/cardcraft/.venv/lib/python3.12/site-packages/pydantic_ai/models/gemini.py", line 176, in request response = _gemini_response_ta.validate_json(await http_response.aread()) ^^^^^^^^^^^^^^^^^^^^^^^

## Steps

1. Issue pydantic/pydantic-ai#631 (closed, 35 comments): I've been getting these sporadically when using Gemini: ``` Traceback (most recent call last): File "/workspaces/cardcraft/.venv/lib/python3.12/site-packages/pydantic_ai/agent.py", line 249, in run model_response, request_usage = await agent_model.request(messages, model_settings) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/workspaces/cardcraft/.venv/lib/python3.12/site-packages/pydantic_ai/models/gemini.py", line 176, in request response = _gemini_response_ta.validate_json(await http_response.aread()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File...

2. pydantic-ai surfaces Gemini's MALFORMED_FUNCTION_CALL finish reason when the model fumbles a function call. There is no library fix; the reliable mitigation from the thread is to simply retry the same request, since the failure is transient on the model's side (one user confirmed resending the exact prompt works). If it happens constantly rather than sporadically, simplify your tool schemas: complex tool definitions make Gemini produce malformed calls more often.

## When to use

You are seeing this: pydantic-ai surfaces Gemini's MALFORMED_FUNCTION_CALL finish reason when the model fumbles a function call. Use this skill when you run into "MALFORMED_FUNCTION finishReason in Gemini candidate".

## When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

## Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

## Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
