Skip to content

Format validated variables in few-shot prompt prefixes - #1097

Open
jihtsan wants to merge 2 commits into
patterns-ai-core:mainfrom
jihtsan:codex/1094-format-few-shot-prefix
Open

jihtsan wants to merge 2 commits into
patterns-ai-core:mainfrom
jihtsan:codex/1094-format-few-shot-prefix

Conversation

@jihtsan

@jihtsan jihtsan commented Oct 31, 2026

Copy link
Copy Markdown

Closes #1094.

FewShotPromptTemplate validates variables from both prefix and suffix, but format left the prefix unchanged. A valid prefix: "Topic: {topic}" consequently sent the placeholder itself to the model.

Format prefix variables in one pass using the same name extraction contract as validation: trim variable names and preserve ignored brace regions as literal text. Inserted values are not rescanned, stored templates stay unchanged, and the suffix retains its existing escaping/replacement behavior. Examples, order and custom separators are preserved.

Validation (Ruby4.0.9, macOS arm64):

  • Original targeted few-shot/structured-parser baseline:15 examples passed.
  • On base, four new prefix regressions fail and six controls pass. Additional interim regressions caught three ignored brace forms and two validator-whitespace cases; these are fixed in the submitted implementation.
  • Complete prompts spec directory: 34 examples,0failures. Covers prefix-only/shared variables, string argument keys, braces/backslashes as inserted data, literal regions, whitespace, unknown placeholders, stored values and custom separators.
  • Repository-wide bundle exec standardrb, bundle exec yardoc, git diff --check: passed. YARD's existing documentation warnings remain.
  • Independent Standards and Spec reviews:0findings for this head.

The upstream has no tracked Gemfile.lock; the generated validation lock and installed bundle were retained as evidence and are not committed. No LLM/provider calls were used. The complete RSpec/Postgres/vector/provider integration matrix and other Ruby/OS versions were not run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FewShotPromptTemplate validates prefix variables but leaves them unresolved when formatting

1 participant