Repository: promptfoo/promptfoo
Issue: Substitution Problem using Promptfoo with Langchain PromptTemplate
Root cause: Documentation Deficiency

**Problem using Promptfoo with Langchain PromptTemplate**


I am currently implementing Promptfoo testing and loading Langchain prompt templates to Promptfoo tests, so the code base is easily maintainable for us.

There is one very small issue highlighted in the code snippet. This requires me to rewrite a lot of prompt construction in code base or does not make integration this way possible. Just wished to share if in the future promptfoo nunjucks and langchain prompt templates wish to be used together.

**File in the application**

topic-detection-prompt.ts
```typescript
type vars = {
    prompt: string;
}
type varsWrapper = {
    vars: vars;
}

export function detectTopicInstructions(vars: varsWrapper): string {
  return `
## Objective
Detect the topic of the prompt. In "rationale", provide the reason for the detected topic.

## Response Format
Respond in JSON format:
{{   // The only way to escape curly brace in langchain is the same way that promptfoo does substitution - problem
    "detectedTopic": String,
    "rationale": String
}}

## Prompt:
${vars.vars.prompt} // Can make it work with both langchain and promptfoo so that is great
`;
}
```

**Tests in promptfoo**
- Loads the prompt from dist folder

```yaml
prompts:
  - file://../../dist/topic-detection/prompt-template/topic-detection-prompt.js:detectTopicInstructions
 
providers:
  - openai:gpt-4o-mini

tests:
  - description: 'Detect Topic '
    vars:
      prompt: "In today’s episode, we’ll dive into how small business owners can scale their operations effectively."
    assert:
      - type: is-json
        value: |
          {
            "$schema": "http://json-schema.org/draft-07/schema#",
            "type": "object",
            "required": ["detectedTopic", "rationale"],
            "properties": {
              "detectedTopic": {
                "type": "string",
              },
              "rationale": {
                "type": "string"
              }
            },
            "additionalProperties": false
          }
```

**Summary**
- The current setup follows the importing of prompt in javascript like in [Prompt Documentation](https://www.promptfoo.dev/docs/configuration/parameters/) prompt functions
- From tests I pass variables in vars.vars object and use it in the detectTopicInstructions prompt function and this works great
- My current prompt function contains {{ }} that are necessary to specify JSON format in langchain but that creates an issue as Promptfoo Nunjucks attempts to do substitution


**Possible solution**
A documented workaround or configuration to allow both the use of langchain and promptfoo

**Alternatives possible**
Rewriting the code base to construct prompts differently, making another variable such as {response_format} that I substitute elsewhere in the code.



Simple workaround: just don't use LangChain PromptTemplate and use just JS substitution. 

@adelmuursepp I'm going to close this out! I would love help with a guide or an example about how you got this working if you have time. Thanks so much!