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.7 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
  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. ## Local Development and Testing
  28. When developing or testing examples locally (especially with coding agents), use the local version instead of the published package:
  29. - **For evaluations with coding agents**: Use `npm run local -- eval -c ...` instead of `npx promptfoo@latest eval -c ...`
  30. - **For other local testing**: Use `npm run local` commands to test your current development version
  31. - This ensures you're testing the local changes rather than the latest published version
  32. - Always test examples with the local version before submitting changes
  33. Example:
  34. ```bash
  35. # Instead of: npx promptfoo@latest eval -c path/to/config.yaml
  36. # Use: npm run local -- eval -c path/to/config.yaml
  37. ```
  38. ## Configuration File Structure
  39. - Always include the YAML schema reference at the top of configuration files:
  40. ```yaml
  41. # yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
  42. ```
  43. - Follow this specific field order in all configuration files:
  44. 1. `description` - A SHORT clear description of what the example demonstrates. Between 3 and 10 words
  45. 2. `env` (optional) - Environment variable settings. Only define if absolutely necessary
  46. 3. `prompts` - The prompts to evaluate
  47. 4. `providers` - The models/providers to test
  48. 5. `defaultTest` (optional) - Default assertions for all tests
  49. 6. `scenarios` (optional) - Named test scenarios
  50. 7. `tests` - Test cases with variables and assertions
  51. - Ensure all configuration files pass YAML lint validation
  52. - When referencing external files, always use the `file://` prefix:
  53. ```yaml
  54. prompts:
  55. - file://prompts/system_message.txt
  56. ```
  57. - For trivial test cases, make them quirky and fun to increase engagement
  58. ## Model Selection
  59. - Always use the latest model versions available in 2025
  60. - For OpenAI, prefer models like:
  61. - `openai:o3-mini`
  62. - `openai:gpt-4o-mini`
  63. - For Anthropic, prefer models like:
  64. - `anthropic:claude-3-7-sonnet-20250219`
  65. - For open-source models, use the latest versions available:
  66. - Latest Llama
  67. - Include a mix of providers when comparing model performance
  68. - Document any model-specific capabilities or limitations in examples
  69. - When demonstrating specialized capabilities (vision, audio, etc.), use models that support those features
  70. ## Environment Variables
  71. - Clearly list all required environment variables at the beginning of the README
  72. - For each environment variable, explain:
  73. - Its purpose
  74. - How to obtain it (for API keys)
  75. - Any default values or constraints
  76. - Include a sample `.env` file or instructions when multiple variables are needed:
  77. ```markdown
  78. ## Environment Variables
  79. This example requires the following environment variables:
  80. - `OPENAI_API_KEY` - Your OpenAI API key
  81. - `ANTHROPIC_API_KEY` - Your Anthropic API key
  82. You can set these in a `.env` file or directly in your environment.
  83. ```
  84. ## Example Quality
  85. - Ensure all examples are functional and up-to-date
  86. - Keep examples as simple as possible while still demonstrating the concept
  87. - Examples should work with publicly available APIs when possible
  88. - Document any required API keys or credentials
  89. - Include placeholder values for secrets/credentials
  90. - Provide instructions for cleaning up resources after running the example
  91. ## Configuration Examples
  92. ### Basic Example
  93. ```yaml
  94. # yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
  95. description: A simple evaluation of translation quality
  96. prompts:
  97. - Translate "{{input}}" to {{language}}
  98. providers:
  99. - openai:o3-mini
  100. - anthropic:claude-3-7-sonnet-latest
  101. tests:
  102. - vars:
  103. input: Hello, world!
  104. language: French
  105. assert:
  106. - type: contains
  107. value: Bonjour
  108. - vars:
  109. input: How are you today?
  110. language: German
  111. assert:
  112. - type: contains
  113. value: heute
  114. ```
  115. ### Example with Optional Fields
  116. ```yaml
  117. # yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
  118. description: Evaluating joke quality across different models
  119. env:
  120. TEMPERATURE: 0.7
  121. prompts:
  122. - file://prompts/joke_prompt.txt
  123. providers:
  124. - id: gpt-5-creative
  125. provider: openai:gpt-5-preview
  126. temperature: $TEMPERATURE
  127. - anthropic:claude-3-7-sonnet-latest
  128. defaultTest:
  129. assert:
  130. - type: javascript
  131. value: return output.length > 20 ? 'pass' : 'fail'
  132. scenarios:
  133. funny-animals:
  134. vars:
  135. topic: animals
  136. style: slapstick
  137. tests:
  138. - vars:
  139. topic: computers
  140. style: dad joke
  141. assert:
  142. - type: llm-rubric
  143. value: Rate this joke on a scale of 1-10 for humor
  144. ```
  145. ## Code Style
  146. - Follow the same code style guidelines as the main project
  147. - Include comments to explain non-obvious parts
  148. - Use descriptive variable and function names
  149. - Format configuration files consistently
  150. - Keep code DRY within reason (examples may duplicate code for clarity)
  151. ## Provider Examples
  152. - When creating examples for specific providers:
  153. - Explain any provider-specific configuration
  154. - Document required environment variables
  155. - Include information about pricing or usage limits
  156. - Highlight unique features or capabilities
  157. - Compare to similar providers where appropriate
  158. - Always use the latest available model versions for that provider
  159. ## Maintenance
  160. - Review examples periodically to ensure they still work
  161. - Update examples when APIs or dependencies change
  162. - Remove outdated examples or mark them as deprecated
  163. - Test examples as part of the CI process when feasible
  164. - Keep dependencies updated in example requirements files
  165. - Update model versions when new ones become available
  166. ## Documentation Integration
  167. - Reference examples in relevant documentation
  168. - Make it clear which features each example demonstrates
  169. - Group related examples together
  170. - Include links to more comprehensive documentation where appropriate
  171. - Consider creating guides that walk through multiple examples
  172. ```
  173. ```
Tip!

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

Comments

Loading...