Repository: promptfoo/promptfoo
Issue: YAMLException when loading nunjucks-templated yaml file
Root cause: External Dependency Breakage

### **Describe the bug**
In a previous version of promptfoo (0.97.0) my team was able to use more advanced nunjucks templating (in our case, imports) to construct our yaml-based prompts. After this version, we get the following error when trying to load our prompts:

```
/usr/local/share/nvm/versions/node/v20.18.0/lib/node_modules/promptfoo/node_modules/js-yaml/lib/loader.js:183
  return new YAMLException(message, mark);
         ^
YAMLException: missed comma between flow collection entries (1:2)

 1 | {% import "system_prompt.yaml" as ...
------^
 2 | {% import "user_prompt.yaml" as u ...
 3 | {{ system_prompt.system_prompt() }}
    at generateError (/usr/local/share/nvm/versions/node/v20.18.0/lib/node_modules/promptfoo/node_modules/js-yaml/lib/loader.js:183:10)
    at throwError (/usr/local/share/nvm/versions/node/v20.18.0/lib/node_modules/promptfoo/node_modules/js-yaml/lib/loader.js:187:9)
    at readFlowCollection (/usr/local/share/nvm/versions/node/v20.18.0/lib/node_modules/promptfoo/node_modules/js-yaml/lib/loader.js:758:7)
    at composeNode (/usr/local/share/nvm/versions/node/v20.18.0/lib/node_modules/promptfoo/node_modules/js-yaml/lib/loader.js:1442:11)
    at readBlockMapping (/usr/local/share/nvm/versions/node/v20.18.0/lib/node_modules/promptfoo/node_modules/js-yaml/lib/loader.js:1104:12)
    at composeNode (/usr/local/share/nvm/versions/node/v20.18.0/lib/node_modules/promptfoo/node_modules/js-yaml/lib/loader.js:1441:12)
    at readDocument (/usr/local/share/nvm/versions/node/v20.18.0/lib/node_modules/promptfoo/node_modules/js-yaml/lib/loader.js:1625:3)
    at loadDocuments (/usr/local/share/nvm/versions/node/v20.18.0/lib/node_modules/promptfoo/node_modules/js-yaml/lib/loader.js:1688:5)
    at Object.load (/usr/local/share/nvm/versions/node/v20.18.0/lib/node_modules/promptfoo/node_modules/js-yaml/lib/loader.js:1714:19)
    at processYamlFile (/usr/local/share/nvm/versions/node/v20.18.0/lib/node_modules/promptfoo/dist/src/prompts/processors/yaml.js:45:38) {
  reason: 'missed comma between flow collection entries',
  mark: {
    name: null,
    buffer: '{% import "system_prompt.yaml" as system_prompt %}\n' +
      '{% import "user_prompt.yaml" as user_prompt %}\n' +
      '{{ system_prompt.system_prompt() }}\n' +
      '{{ user_prompt.user_prompt(example) }}\n',
    position: 1,
    line: 0,
    column: 1,
    snippet: ' 1 | {% import "system_prompt.yaml" as ...\n' +
      '------^\n' +
      ' 2 | {% import "user_prompt.yaml" as u ...\n' +
      ' 3 | {{ system_prompt.system_prompt() }}'
  }
}
```

### **To Reproduce**
1. Install promptfoo with a version > 0.97.0
2. Use the below promptfooconfig and nunjucks-templated prompt files:

#### promptfooconfig.yaml
```
description: "Yaml bug example"

custom-metadata:
  metadata:
    workspace: GenAI
    app: debug
    feature: debug

tags:
  $ref: '#/custom-metadata/metadata'

tests:
  - description: 'Test if output is equal to the expected value'
    vars:
      example: 'Hello, World!'
    assert:
      - type: equals
        value: 'Hello, World!'

prompts:
  - id: file://example.yaml
    label: example

providers:
  - id: openai:gpt-4o
    config:
      seed: 1234
      temperature: 0.0000001
      max_tokens: 1000
      passthrough:
        $ref: '#/custom-metadata'
    prompts:
      - example
```

#### example.yaml
```
{% import "system_prompt.yaml" as system_prompt %}
{% import "user_prompt.yaml" as user_prompt %}
{{ system_prompt.system_prompt() }}
{{ user_prompt.user_prompt(example) }}
```

#### system_prompt.yaml
```
{%- macro system_prompt() -%}
- role: system
  content: |-
    You are a helpful ai assistant.
    Please do as the user asks.
{% endmacro %}
```

#### user_prompt.yaml
```
{% macro user_prompt(phrase) %}
- role: user
  content: |-
    Repeat the following: {{ phrase }}
{% endmacro %}
```

### **Expected behavior**
On version 0.97.0 (and some prior) running promptfoo eval with the above config and prompt files passes:

```
promptfoo eval --env-file ".env" --config "promptfooconfig.yaml" --output "result.yaml" --no-table

============================================================================================================================================================================================================
⚠️ The current version of promptfoo 0.97.0 is lower than the latest available version 0.100.5.

Please run npx promptfoo@latest or npm install -g promptfoo@latest to update.
============================================================================================================================================================================================================

Loading environment variables from .env
Running 1 concurrent evaluations with 4 threads...
Creating cache folder at /home/codespace/.promptfoo/cache.
[████████████████████████████████████████] 100% | ETA: 0s | 1/1 | openai:gpt-4o "{% import " example=He
Writing output to result.yaml
============================================================================================================================================================================================================
✔ Evaluation complete.

» Run promptfoo view to use the local web viewer
» Run promptfoo share to create a shareable URL
» This project needs your feedback. What's one thing we can improve? https://forms.gle/YFLgTe1dKJKNSCsU7
============================================================================================================================================================================================================
Successes: 1
Failures: 0
Pass Rate: 100.00%
Total tokens: 37 / Prompt tokens: 33 / Completion tokens: 4 / Cached tokens: 0
Done.
```

### Screenshots

In version 0.97.0 the final prompt was also in the viewer:
![image](https://github.com/user-attachments/assets/2ffc085a-1917-4367-b4da-4c1ebe80c6d0)
![image](https://github.com/user-attachments/assets/36d9942c-e4d2-4150-87ea-7895f771ac3a)

This is resolved in [0.101.2](https://github.com/promptfoo/promptfoo/releases/tag/0.101.2). Please update to the latest version and let us know if you encounter any further issues. If you have any additional questions, feel free to reach out or open a new issue. Thanks again for using Promptfoo!