Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

examples.mdc 6.0 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
  1. ---
  2. description: This rule provides guidance for creating and maintaining examples in the promptfoo project, which has an extensive collection of example configurations.
  3. globs: examples/**/*
  4. alwaysApply: false
  5. ---
  6. # Examples Development Guidelines
  7. ## Example Structure
  8. - Each example should have its own directory with a clear, descriptive name
  9. - The README.md must begin with the folder name as an H1 heading:
  10. ```markdown
  11. # example-name (human readable name)
  12. ```
  13. - Every example README must include how to run it with:
  14. ````markdown
  15. You can run this example with:
  16. ```bash
  17. npx promptfoo@latest init --example example-name
  18. ```
  19. ````
  20. - Include a comprehensive README.md that explains:
  21. - The purpose of the example
  22. - Required prerequisites or setup
  23. - Step-by-step instructions for running the example
  24. - Expected outputs or results
  25. - Structure examples consistently with common patterns across the project
  26. - Include a working `promptfooconfig.yaml` (or equivalent) file
  27. ## Configuration File Structure
  28. - Always include the YAML schema reference at the top of configuration files:
  29. ```yaml
  30. # yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
  31. ```
  32. - Follow this specific field order in all configuration files:
  33. 1. `description` - A SHORT clear description of what the example demonstrates. Between 3 and 10 words
  34. 2. `env` (optional) - Environment variable settings. Only define if absolutely necessary
  35. 3. `prompts` - The prompts to evaluate
  36. 4. `providers` - The models/providers to test
  37. 5. `defaultTest` (optional) - Default assertions for all tests
  38. 6. `scenarios` (optional) - Named test scenarios
  39. 7. `tests` - Test cases with variables and assertions
  40. - Ensure all configuration files pass YAML lint validation
  41. - When referencing external files, always use the `file://` prefix:
  42. ```yaml
  43. prompts:
  44. - file://prompts/system_message.txt
  45. ```
  46. - For trivial test cases, make them quirky and fun to increase engagement
  47. ## Model Selection
  48. - Always use the latest model versions available in 2025
  49. - For OpenAI, prefer models like:
  50. - `openai:o3-mini`
  51. - `openai:gpt-4o-mini`
  52. - For Anthropic, prefer models like:
  53. - `anthropic:claude-3-7-sonnet-20250219`
  54. - For open-source models, use the latest versions available:
  55. - Latest Llama
  56. - Include a mix of providers when comparing model performance
  57. - Document any model-specific capabilities or limitations in examples
  58. - When demonstrating specialized capabilities (vision, audio, etc.), use models that support those features
  59. ## Environment Variables
  60. - Clearly list all required environment variables at the beginning of the README
  61. - For each environment variable, explain:
  62. - Its purpose
  63. - How to obtain it (for API keys)
  64. - Any default values or constraints
  65. - Include a sample `.env` file or instructions when multiple variables are needed:
  66. ```markdown
  67. ## Environment Variables
  68. This example requires the following environment variables:
  69. - `OPENAI_API_KEY` - Your OpenAI API key
  70. - `ANTHROPIC_API_KEY` - Your Anthropic API key
  71. You can set these in a `.env` file or directly in your environment.
  72. ```
  73. ## Example Quality
  74. - Ensure all examples are functional and up-to-date
  75. - Keep examples as simple as possible while still demonstrating the concept
  76. - Examples should work with publicly available APIs when possible
  77. - Document any required API keys or credentials
  78. - Include placeholder values for secrets/credentials
  79. - Provide instructions for cleaning up resources after running the example
  80. ## Configuration Examples
  81. ### Basic Example
  82. ```yaml
  83. # yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
  84. description: A simple evaluation of translation quality
  85. prompts:
  86. - Translate "{{input}}" to {{language}}
  87. providers:
  88. - openai:o3-mini
  89. - anthropic:claude-3-7-sonnet-latest
  90. tests:
  91. - vars:
  92. input: Hello, world!
  93. language: French
  94. assert:
  95. - type: contains
  96. value: Bonjour
  97. - vars:
  98. input: How are you today?
  99. language: German
  100. assert:
  101. - type: contains
  102. value: heute
  103. ```
  104. ### Example with Optional Fields
  105. ```yaml
  106. # yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
  107. description: Evaluating joke quality across different models
  108. env:
  109. TEMPERATURE: 0.7
  110. prompts:
  111. - file://prompts/joke_prompt.txt
  112. providers:
  113. - id: gpt-5-creative
  114. provider: openai:gpt-5-preview
  115. temperature: $TEMPERATURE
  116. - anthropic:claude-3-7-sonnet-latest
  117. defaultTest:
  118. assert:
  119. - type: javascript
  120. value: return output.length > 20 ? 'pass' : 'fail'
  121. scenarios:
  122. funny-animals:
  123. vars:
  124. topic: animals
  125. style: slapstick
  126. tests:
  127. - vars:
  128. topic: computers
  129. style: dad joke
  130. assert:
  131. - type: llm-rubric
  132. value: Rate this joke on a scale of 1-10 for humor
  133. ```
  134. ## Code Style
  135. - Follow the same code style guidelines as the main project
  136. - Include comments to explain non-obvious parts
  137. - Use descriptive variable and function names
  138. - Format configuration files consistently
  139. - Keep code DRY within reason (examples may duplicate code for clarity)
  140. ## Provider Examples
  141. - When creating examples for specific providers:
  142. - Explain any provider-specific configuration
  143. - Document required environment variables
  144. - Include information about pricing or usage limits
  145. - Highlight unique features or capabilities
  146. - Compare to similar providers where appropriate
  147. - Always use the latest available model versions for that provider
  148. ## Maintenance
  149. - Review examples periodically to ensure they still work
  150. - Update examples when APIs or dependencies change
  151. - Remove outdated examples or mark them as deprecated
  152. - Test examples as part of the CI process when feasible
  153. - Keep dependencies updated in example requirements files
  154. - Update model versions when new ones become available
  155. ## Documentation Integration
  156. - Reference examples in relevant documentation
  157. - Make it clear which features each example demonstrates
  158. - Group related examples together
  159. - Include links to more comprehensive documentation where appropriate
  160. - Consider creating guides that walk through multiple examples
  161. ```
  162. ```
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...