Repository: promptfoo/promptfoo
Issue: The model-graded-closedqa response check is too strict
Root cause: Validation Gap

**Describe the bug**
When gemma2:9b is used for model-graded-closedqa, the response often ends with a white space and a newline. It results in a malformed response error.

**To Reproduce**

1. Install ollama
2. ollama pull llama3:8b and gemma2:9b
3. Run eval with the following configuration:

```closedqa.yaml
prompts:
  - |
    Act as a spelling corrector and improver. Reply with the fixed text ONLY.

    Text: {{text}}

    Fixed Text:

providers:
  - id: ollama:chat:llama3:8b
    config:
      temperature: 0.2
      seed: 42

defaultTest:
  options:
    provider:
      id: ollama:chat:gemma2:9b
      config:
        temperature: 0.2
        seed: 42

tests:
  - vars:
      text: |
        This is a test of fix typpo

    assert:
      - type: model-graded-closedqa
        value: The output should not include explanations of the changes made and just provides the fixed text ONLY.
```

```
$ ollama --version
ollama version is 0.3.0

$ LOG_LEVEL=debug npm run local -- eval --no-cache

(snip.)

Eval #1 complete (1 of 1)
At least one evaluation failure occurred. This might be caused by the underlying call to the provider, or a test failure. Context:
[{"provider":{"id":"ollama:chat:llama3:8b"},"prompt":{"raw":"Act as a spelling corrector and improver. Reply with the fixed text ONLY.\n\nText: This is a test of fix typpo\n\nFixed Text:\n","label":"Act as a spelling corrector and improver. Reply with the fixed text ONLY.\n\nText: {{text}}\n\nFixed Text:\n"},"vars":{"text":"This is a test of fix typpo"},"response":{"output":"This is a test of fix typo"},"success":false,"score":0,"namedScores":{},"latencyMs":7872,"error":"Model grader produced a malformed response:\n1. The criterion states that the output should only contain the fixed text. \n2. The submission includes \"This is a test of fix typo\" which is the corrected text.\n3.  The submission does not include any additional text explaining the changes made.\n\nY\nY \n","gradingResult":{"pass":false,"score":0,"reason":"Model grader produced a malformed response:\n1. The criterion states that the output should only contain the fixed text. \n2. The submission includes \"This is a test of fix typo\" which is the corrected text.\n3.  The submission does not include any additional text explaining the changes made.\n\nY\nY \n","namedScores":{},"tokensUsed":{"total":0,"prompt":0,"completion":0,"cached":0},"componentResults":[{"assertion":{"type":"model-graded-closedqa","value":"The output should not include explanations of the changes made and just provides the fixed text ONLY."},"pass":false,"score":0,"reason":"Model grader produced a malformed response:\n1. The criterion states that the output should only contain the fixed text. \n2. The submission includes \"This is a test of fix typo\" which is the corrected text.\n3.  The submission does not include any additional text explaining the changes made.\n\nY\nY \n","tokensUsed":{"total":0,"prompt":0,"completion":0,"cached":0}}],"assertion":null}}]
```

Note that The grader's answer is Y, but there is an extra white space and a newline at the end.

> Y\nY \n

**Expected behavior**
Ignore a white space and a newline at the end. The current implementation of response check is too strict.

**Screenshots**
<img width="1722" alt="image" src="https://github.com/user-attachments/assets/b91a3eb5-a826-40fc-9bd0-a73ef528c948">

**System information (please complete the following information):**

- Promptfoo version: 0.73.7

**Additional context**

In general, this problem can occur with models other than gemma2, but seems to occur more often with gemma2.