Skip to content

Add context hardening: trim, allow/deny regex, and onContextOverflow handling#7

Merged
PredictabilityAtScale merged 1 commit into
mainfrom
codex/add-input-validation-features-for-prompts-a4xonk
Apr 22, 2026
Merged

Add context hardening: trim, allow/deny regex, and onContextOverflow handling#7
PredictabilityAtScale merged 1 commit into
mainfrom
codex/add-input-validation-features-for-prompts-a4xonk

Conversation

@PredictabilityAtScale
Copy link
Copy Markdown
Owner

Motivation

  • Provide per-input runtime hardening for context variables to reduce prompt-injection and oversize issues.
  • Allow callers to transform oversized context values before rendering via a callback so large inputs can be summarized/redacted.

Description

  • Add trim, allow_regex, and deny_regex to the context input schema and expose them through ContextInputDefinition, normalizeContextInput, and Zod ContextInputDefinitionObjectSchema.
  • Implement sanitizeContextVariables(...) in src/context.ts to run onContextOverflow callbacks, trim values to max_size, and enforce allow_regex / deny_regex, and integrate it into PromptOpsKit.renderPrompt and provider input handling so sanitized variables are used for rendering.
  • Add new error/warning codes and static checks in validation: POK013 for invalid regex, POK014 when trim is set without max_size, and runtime errors POK031/POK032 for allow/deny failures; keep POK030 for size warnings.
  • Update public APIs and types to accept an optional onContextOverflow callback in RenderPromptOptions and RuntimeRenderOptions, and update docs, README, website, and examples to document the new controls.
  • Add unit tests covering trimming behavior, explicit non-trimming, allowlist/blocklist validation, invalid regex validation, trim-without-size warning, and onContextOverflow callback integration.

Testing

  • Ran the unit test suite (npm test) including updated tests/runtime-context-placeholders.test.ts and tests/validation.test.ts which exercise trimming, regex validation, overflow callback, and validation warnings/errors, and all tests passed.

Codex Task

@PredictabilityAtScale PredictabilityAtScale merged commit 2fff3d0 into main Apr 22, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant