You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`context.inputs`| `Array<string | { name, max_size?, trim?, allow_regex?, deny_regex? }>` | no | Declared variable names used in templates, with optional size budgets and runtime hardening controls |
69
+
|`context.inputs`| `Array<string | { name, max_size?, trim?, allow_regex?, deny_regex?, non_empty?, reject_secrets? }>` | no | Declared variable names used in templates, with optional size budgets and runtime hardening controls |
70
70
|`context.history`| object | no |`{ max_items: number }`|
71
71
|`includes`| string[]| no | Relative paths to other prompt files to include |
72
72
|`environments`| object | no | Per-environment overrides (see Overrides) |
@@ -102,6 +102,8 @@ Rules:
102
102
- Use object-form inputs with `max_size` when a variable is likely to grow large and should trigger early warnings
103
103
- Use `trim` to enforce byte budgets before interpolation when `max_size` is set
104
104
- Use `allow_regex` for allowlist checks and `deny_regex` for blocklist checks on risky inputs
105
+
- Prefer structured regexes like `{ pattern, flags }`; `/pattern/i` strings are also accepted and normalized internally
106
+
- Use `non_empty: true` for required user text and `reject_secrets: true` for common secret redaction checks
105
107
- Escape literal braces with `\{{` and `\}}`
106
108
- In strict mode, missing variables throw an error
107
109
- In permissive mode, unresolved placeholders are left intact
@@ -119,6 +121,8 @@ context:
119
121
If a rendered value exceeds `max_size`, `renderPrompt()` emits a non-blocking `POK030` warning.
120
122
At render time, callers can also pass `onContextOverflow` to transform oversized values before warnings/rendering.
121
123
124
+
Malformed `allow_regex` and `deny_regex` values fail during `validate` and `compile`, not just at render time. When regex compilation fails, the error includes the prompt id, variable name, field name, and raw configured value.
125
+
122
126
Example: this is the minimal valid shape for a prompt that references
123
127
`{{ pull_request }}` even when provider/model are inherited from defaults:
`validatePrompt()` covers schema, include-graph, and variable declaration issues. Render-time context size warnings are produced by `renderPrompt()`, not validation.
117
+
`validatePrompt()` covers schema, include-graph, variable declaration issues, and context regex compilation. Render-time context size warnings are produced by `renderPrompt()`, not validation.
`validateAsset()` reports malformed `allow_regex` and `deny_regex` values before runtime, including the prompt id, variable name, field name, and raw configured value in the error message.
Includes are resolved during compilation so compiled artifacts are self-sufficient. The output directory is cleared by default before compiling (unless `--no-clean` is set).
82
84
85
+
Compilation runs validation before writing artifacts. Invalid `allow_regex` or `deny_regex` definitions fail the compile step early with `POK013` instead of surfacing later during `renderPrompt()`.
86
+
83
87
If you omit `<out>`, the CLI chooses `./.generated-prompts/json` for `json` and `./.generated-prompts/esm` for `esm`.
84
88
85
89
`defaults.md` files are treated as configuration inputs and are not compiled as standalone prompts.
Copy file name to clipboardExpand all lines: docs/getting-started.md
+7-4Lines changed: 7 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,8 +43,11 @@ sampling:
43
43
temperature: 0.7
44
44
context:
45
45
inputs:
46
-
- user_message
47
-
- app_context
46
+
- name: user_message
47
+
non_empty: true
48
+
reject_secrets: true
49
+
- name: app_context
50
+
allow_regex: "/^[A-Za-z0-9 _-]+$/i"
48
51
includes:
49
52
- ./shared/tone.md
50
53
---
@@ -114,15 +117,15 @@ Your application owns the HTTP call — PromptOpsKit produces the request body o
114
117
npx promptopskit validate ./prompts
115
118
```
116
119
117
-
This checks all `.md` files for schema errors, unknown front matter keys (with "did you mean?" suggestions), and variable usage mismatches.
120
+
This checks all `.md` files for schema errors, unknown front matter keys (with "did you mean?" suggestions), variable usage mismatches, and malformed context regex definitions.
118
121
119
122
## Compile for production
120
123
121
124
```bash
122
125
npx promptopskit compile
123
126
```
124
127
125
-
Pre-compiles `.md` files to JSON (or ESM) artifacts so deployments skip parsing entirely. Add to your build scripts:
128
+
Pre-compiles `.md` files to JSON (or ESM) artifacts so deployments skip parsing entirely. Compilation validates prompt files first, so malformed regex definitions fail before artifacts are written. Add to your build scripts:
Copy file name to clipboardExpand all lines: docs/prompt-format.md
+13-3Lines changed: 13 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -169,15 +169,19 @@ Each entry can be either a string variable name or an object with:
169
169
- `name` — the template variable name
170
170
- `max_size`— optional UTF-8 byte limit for the injected value
171
171
- `trim`— optional trim-to-budget (`true`/`end` keeps first bytes, `start` keeps trailing bytes) applied when `max_size` is set
172
-
- `allow_regex`— optional allowlist regex; input must match (throws `POK031` on mismatch)
173
-
- `deny_regex`— optional blocklist regex; input must not match (throws `POK032` on match)
172
+
- `allow_regex`— optional allowlist regex; accepts `"pattern"`, `/pattern/i`, or `{ pattern, flags }` and throws `POK031` on mismatch
173
+
- `deny_regex`— optional blocklist regex; accepts `"pattern"`, `/pattern/i`, or `{ pattern, flags }` and throws `POK032` on match
174
+
- `non_empty`— optional boolean validator; throws `POK033` when the final value is blank or whitespace-only
175
+
- `reject_secrets`— optional boolean validator; throws `POK034` when the value matches the built-in secret detector
174
176
175
177
The validator warns about:
176
178
- Variables used in templates but not declared in `context.inputs`
177
179
- Variables declared in `context.inputs` but never used
178
180
179
181
At render time, PromptOpsKit also emits a non-blocking `POK030` warning when a provided variable exceeds its declared `max_size`. In source and auto modes, the warning is also written to `console.warn` to make local development issues visible early.
180
182
183
+
Malformed `allow_regex` and `deny_regex` values fail during `validate` and `compile` with `POK013`, so bad patterns are caught before runtime.
Copy file name to clipboardExpand all lines: docs/validation.md
+15-5Lines changed: 15 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Validation
2
2
3
-
PromptOpsKit validates prompts at multiple levels — schema structure, front matter keys, variable usage, and include graphs. Render-time context size limits are checked separately during prompt rendering.
3
+
PromptOpsKit validates prompts at multiple levels — schema structure, front matter keys, variable usage, context regex compilation, and include graphs. Render-time context size limits are checked separately during prompt rendering.
4
4
5
5
## Quick start
6
6
@@ -34,8 +34,10 @@ const result = await kit.validatePrompt('support/reply');
34
34
|`POK010`| Warning | Unknown front matter key (with "did you mean?" suggestion) |
35
35
|`POK011`| Warning | Variable used in template but not declared in `context.inputs`|
36
36
|`POK012`| Warning | Variable declared in `context.inputs` but never used |
|`POK013`| Error | Invalid context regex pattern (`allow_regex` or `deny_regex`), including prompt id, variable name, field name, and raw configured value|
38
38
|`POK014`| Warning |`trim` configured without `max_size` (trim-to-budget skipped) |
0 commit comments