Repository: promptfoo/promptfoo
Issue: Gemini - Consistent Error "Expected at least one candidate in AI Studio API response."
Root cause: External Dependency Breakage

**Describe the bug**
Using `google:gemini-2.5-flash` model I keep getting this error. If I switch to 1.5 (`google:gemini-1.5-flash`) the errors don't seem to occur.

```
[ERROR] Error: Expected at least one candidate in AI Studio API response.
```

**To Reproduce**

Its been occurring quite consistently. This is probably more complicated example than needed - but 2 of the 3 requests failed for me (which is especially strange)

```
[ERROR] Error: Expected at least one candidate in AI Studio API response.
```

```prompt.json
[
  {
    "role": "system",
    "content": "{{ system_message }}"
  }
  {% for message in conversation %}
  ,
  {
    "role": "{{ message.role }}",
    "content": "{{ message.content }}"
  }
  {% endfor %}
]
```

```yaml
# promptfooconfig.yaml

prompts:
  - file://prompt.json

providers:
  - google:gemini-2.5-flash

defaultTest:
  vars:
    system_message: "This is your single large system prompt. You are a helpful assistant that provides concise and accurate information. You should be friendly and professional."

tests:
  - description: "Conversation about geography"
    vars:
      conversation:
        - role: user
          content: "What is the capital of France?"
        - role: assistant
          content: "The capital of France is Paris."
        - role: user
          content: "What is its population?"

  - description: "Conversation about literature"
    vars:
      conversation:
        - role: user
          content: "Who wrote 'To Kill a Mockingbird'?"
        - role: assistant
          content: "Harper Lee wrote 'To Kill a Mockingbird'."
        - role: user
          content: "What is the main theme of the book?"

  - description: "A shorter conversation"
    vars:
      conversation:
        - role: user
          content: "What is the formula for water?"
```

**Expected behavior**

The prompts are simple and (should be) straight forward - there should be no error occuring.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**System information:**

```
===================================================================================================================================
Promptfoo Debug Information
===================================================================================================================================
{
  "version": "0.117.10",
  "platform": {
    "os": "darwin",
    "release": "24.3.0",
    "arch": "arm64",
    "nodeVersion": "v22.14.0"
  },
  "env": {},
  "configInfo": {
    "defaultConfigPath": "/Users/gb/github-gigpro/poc-voiceflow/promptfooconfig.yaml",
    "configExists": true,
    "configContent": {
      "config": {
        "tags": {},
        "prompts": [
          "file:///Users/gb/github-gigpro/poc-voiceflow/prompt.json"
        ],
        "providers": [
          "google:gemini-1.5-flash"
        ],
        "tests": [
          {
            "description": "Conversation about geography",
            "vars": {
              "conversation": [
                {
                  "role": "user",
                  "content": "What is the capital of France?"
                },
                {
                  "role": "assistant",
                  "content": "The capital of France is Paris."
                },
                {
                  "role": "user",
                  "content": "What is its population?"
                }
              ]
            }
          },
          {
            "description": "Conversation about literature",
            "vars": {
              "conversation": [
                {
                  "role": "user",
                  "content": "Who wrote 'To Kill a Mockingbird'?"
                },
                {
                  "role": "assistant",
                  "content": "Harper Lee wrote 'To Kill a Mockingbird'."
                },
                {
                  "role": "user",
                  "content": "What is the main theme of the book?"
                }
              ]
            }
          },
          {
            "description": "A shorter conversation",
            "vars": {
              "conversation": [
                {
                  "role": "user",
                  "content": "What is the formula for water?"
                }
              ]
            }
          }
        ],
        "scenarios": [],
        "env": {},
        "sharing": true,
        "defaultTest": {
          "vars": {
            "system_message": "file://system_prompt.txt"
          },
          "assert": [],
          "options": {},
          "metadata": {}
        },
        "outputPath": [],
        "extensions": [],
        "metadata": {}
      },
      "testSuite": {
        "tags": {},
        "prompts": [
          {
            "raw": "[\n  {\n    \"role\": \"system\",\n    \"content\": \"{{ system_message }}\"\n  }\n  {% for message in conversation %}\n  ,\n  {\n    \"role\": \"{{ message.role }}\",\n    \"content\": \"{{ message.content }}\"\n  }\n  {% endfor %}\n]",
            "label": "/Users/gb/github-gigpro/poc-voiceflow/prompt.json: [\n  {\n    \"role\": \"system\",\n    \"content\": \"{{ system_message }}\"\n  }\n  {% for message in conversation %}\n  ,\n  {\n    \"role\": \"{{ message.role }}\",\n    \"content\": \"{{ message.content }}\"\n  }\n  {% endfor %}\n]"
          }
        ],
        "providers": [
          {
            "env": {},
            "modelName": "gemini-1.5-flash",
            "config": {
              "basePath": "/Users/gb/github-gigpro/poc-voiceflow"
            },
            "mcpClient": null,
            "initializationPromise": null,
            "label": ""
          }
        ],
        "providerPromptMap": {},
        "tests": [
          {
            "description": "Conversation about geography",
            "vars": {
              "conversation": [
                {
                  "role": "user",
                  "content": "What is the capital of France?"
                },
                {
                  "role": "assistant",
                  "content": "The capital of France is Paris."
                },
                {
                  "role": "user",
                  "content": "What is its population?"
                }
              ]
            }
          },
          {
            "description": "Conversation about literature",
            "vars": {
              "conversation": [
                {
                  "role": "user",
                  "content": "Who wrote 'To Kill a Mockingbird'?"
                },
                {
                  "role": "assistant",
                  "content": "Harper Lee wrote 'To Kill a Mockingbird'."
                },
                {
                  "role": "user",
                  "content": "What is the main theme of the book?"
                }
              ]
            }
          },
          {
            "description": "A shorter conversation",
            "vars": {
              "conversation": [
                {
                  "role": "user",
                  "content": "What is the formula for water?"
                }
              ]
            }
          }
        ],
        "scenarios": [],
        "defaultTest": {
          "metadata": {},
          "options": {},
          "vars": {
            "system_message": "file://system_prompt.txt"
          },
          "assert": []
        },
        "nunjucksFilters": {},
        "extensions": []
      },
      "basePath": "/Users/gb/github-gigpro/poc-voiceflow"
    }
  }
}
```

- Promptfoo version:  0.117.10

**Additional context**

The error has been occurring quite consistently with Gemini. I'd imagine its trying to make some unexpected call or response format.


Thanks for the report @gregberns.  https://github.com/promptfoo/promptfoo/pull/5386 should fix and will be in the next release