Is there an existing issue for this?
Which plugins are affected?
Other
Which platforms are affected?
Web
Description
In api.dart, firebase_ai isn't handling the MALFORMED_FUNCTION_CALL finish reason, and instead throws an exception.
There should be a FinishReason enum for malformedFunctionCall and it should handle it and return it instead of throwing.
Here's the current code from api.dart that is the problem:
static FinishReason parseValue(Object jsonObject) {
return switch (jsonObject) {
'UNSPECIFIED' => FinishReason.unknown,
'STOP' => FinishReason.stop,
'MAX_TOKENS' => FinishReason.maxTokens,
'SAFETY' => FinishReason.safety,
'RECITATION' => FinishReason.recitation,
'OTHER' => FinishReason.other,
_ => throw FormatException('Unhandled FinishReason format', jsonObject),
};
}
Reproducing the issue
Create an app and give it an invalid function call to send to Gemini. When it responds with a response that looks like this:
{
"candidates": [
{
"finishReason": "MALFORMED_FUNCTION_CALL",
"usageMetadata": {
"promptTokenCount": 4474,
"totalTokenCount": 4474,
"promptTokensDetails": [
{
"modality": "TEXT",
"tokenCount": 4474
}
]
},
"modelVersion": "gemini-2.5-flash",
"responseId": "aaaaaaa-bbbbbbbbb"
}
]
}
You will get a FormatException.
Firebase Core version
firebase_ai 3.4.0
Flutter Version
3.38.0
Relevant Log Output
Flutter dependencies
Additional context and comments
No response
Is there an existing issue for this?
Which plugins are affected?
Other
Which platforms are affected?
Web
Description
In
api.dart, firebase_ai isn't handling the MALFORMED_FUNCTION_CALL finish reason, and instead throws an exception.There should be a FinishReason enum for malformedFunctionCall and it should handle it and return it instead of throwing.
Here's the current code from
api.dartthat is the problem:Reproducing the issue
Create an app and give it an invalid function call to send to Gemini. When it responds with a response that looks like this:
{ "candidates": [ { "finishReason": "MALFORMED_FUNCTION_CALL", "usageMetadata": { "promptTokenCount": 4474, "totalTokenCount": 4474, "promptTokensDetails": [ { "modality": "TEXT", "tokenCount": 4474 } ] }, "modelVersion": "gemini-2.5-flash", "responseId": "aaaaaaa-bbbbbbbbb" } ] }You will get a
FormatException.Firebase Core version
firebase_ai 3.4.0
Flutter Version
3.38.0
Relevant Log Output
Flutter dependencies
Additional context and comments
No response