Repository: promptfoo/promptfoo
Issue: "named_scores" are not displayed as expected
Root cause: Validation Gap

Hello,
The **named_scores** are correctly exported to the json file, but they are not displayed on the promptfoo UI.

Here you can see the computed values available in the Json
![image](https://github.com/user-attachments/assets/08972910-320a-46ef-a3ee-adb3e4b339b3)

But these extra metrics do not appears on the promptfoo UI (they are returned by the same script as "Rags Answer Similarity").
![image](https://github.com/user-attachments/assets/3eb960b3-b054-424d-b138-8ed0ad00e2aa)

I can see the 2 other metrics called "Demo metric", "Exact Match", but I see the main "Ragas Answer Similarity" instead of "answer_similarity", "answer_correctness" and "answer_relevancy" as expected.

![image](https://github.com/user-attachments/assets/f4cc5061-5189-4bc1-904c-02201513111a)


Here is the simplified version of the "Ragas Answer Similarity python script (with which I obviously try to return more than just similarity).

```
def get_assert(output: str, context) -> Union[bool, float, Dict[str, Any]]:
    return {
      'pass': True,
      'score': 0.11,
      'reason': 'Looks good to me',
      'named_scores': {
         'answer_similarity': 0.12,
         'answer_correctness': 0.13,
         'answer_relevancy': 0.14,
      }
    }
```

**Expected behavior**
Ideally, the "named_scores" should display next to the other scores as explained [here](https://www.promptfoo.dev/docs/configuration/expected-outputs/python/)

![image](https://github.com/user-attachments/assets/3e1ec4c5-6770-4d0b-a9d0-d36417cfece6)


Also, we should be able to return only the named scores without the main score (in my case I want ONE python script to compute several ragas metrics at once, and hence I want to return and display several metrics)

**System information (please complete the following information):**

- Promptfoo version: 0.84.1

Also experiencing the same issue here

Seems like we have to modify namedScores in evaluatorResult instead of componentResult https://www.promptfoo.dev/docs/configuration/reference/#gradingresult

I tried it using hooks and it is now showing the namedScores I want
```javascript
async function extensionHook(hookName, context) {
  if (hookName === 'afterEach') {
    // console.log('context.result', context.result)
    // console.log(
    //   `Test completed: ${context.test.description || ''}. Pass: ${context.result.success || false}`,
    // );
    // Loop through componentResults and aggregate the namedScores
    const aggregatedNamedScores = {};

    if (context.result.gradingResult && context.result.gradingResult.componentResults) {
      context.result.gradingResult.componentResults.forEach(component => {
        if (component.namedScores) {
          Object.entries(component.namedScores).forEach(([key, value]) => {
            if (aggregatedNamedScores[key] === undefined) {
              aggregatedNamedScores[key] = [];
            }
            aggregatedNamedScores[key].push(value);
          });
        }
      });
    }

    // Calculate average for each named score
    Object.keys(aggregatedNamedScores).forEach(key => {
      const scores = aggregatedNamedScores[key];
      const average = scores.reduce((sum, score) => sum + score, 0) / scores.length;

      context.result.gradingResult.namedScores[key] = average;
    });
  }
}

module.exports = extensionHook;`

Hi @Valkea (CC: @AmineDjeghri, @tan-z-tan, @albertlieyingadrian) 

We just released [0.88.0](https://github.com/promptfoo/promptfoo/releases/tag/0.88.0), which includes improvements for displaying named_scores. Thanks to @khp for the fix and @albertlieyingadrian for a great workaround. Please let us know if you encounter any other issues!




I can confirm it works. 

I can't find a way to get only the NamedScores without the main Score, but all in all we can deal with it.
Thank you very much to @khp and the promptfoo team.

Hey @Valkea, just curious, how are you getting the main score to show up in the UI? Is there a way other than using the `metric` tag under the assert? I ran my testing without `metric` set and it only shows the `namedScores`.