Repository navigation
Description
Problem or Motivation
Values enter prompts in 4 ways: str.format (4 sites), chained str.replace (3 sites; one uses {{name}} markers in fill_prompt, src/devops_cli/roadmap/implement/implement_shell_policy.py:541), f-string concatenation (4 sites) and constants in Python. No prompt can take a repository fact. There are 37 load_task_prompt calls in 24 files. A probe shows that 67 of 72 task and persona files render byte-identical through a Jinja2 SandboxedEnvironment with StrictUndefined.
Proposed Solution & Architectural Design
- Change
load_task_prompt(name, **context)to render through one cached Jinja2SandboxedEnvironment:StrictUndefined,keep_trailing_newline, notrim_blocksorlstrip_blocks, and autoescape off. - Add no new function and no
ChoiceLoader. Read no prompt from a target repository, because a target that overrides a prompt can change the job rules. - All 37 call sites stay. Only the prompts that hold a project fact get context: stage_change, stage_split, stage_tools_research, implement_step and alternatives.
roadmap_implement_step.mdgets its tables through context. Removefill_promptand itsstr.replace.- The personas reader and the benchmark reader stay plain text, because 3 benchmark files hold GitHub
${{ }}expressions. stage_plan_record.prompt_versionhashes the raw template plus the context values, so a call with no context does not raise.
Target Subsystem
AI & Agentic Review Pipeline (src/devops_cli/ai/task_loader.py).
Existing Tool Considered
Jinja2 3.1.6 is already a dependency, and its SandboxedEnvironment is the standard way to render a template with limited access. string.Template has no conditional blocks. LangChain PromptTemplate adds a dependency and uses Jinja2 or f-strings too. Cost of the wiring: about 40 lines and 1 test, about 150,000 tokens and 2 hours to build, about 3,000 tokens a month to keep.
Acceptance Criteria
- A test renders each prompt name that the code uses, with its real context, and asserts no
UndefinedError. - A test: for each prompt with no variables, the rendered text equals the file text.
- A test: the rendered implement step prompt equals the
fill_promptoutput of today for devops-cli. -
git grep -n 'fill_prompt\|PROGRAMS_PLACEHOLDER' srcgives 0. - jinja2 stays the only template dependency (3.1.6).
Dependencies
#4630 (a missing prompt raises).
Source: #4627
Proposed design
Problem statement
Prompts take their values in four ways, and no prompt can take a repository fact. The change renders a task prompt through one cached Jinja2 SandboxedEnvironment when its caller passes a context, gives the implement step prompt its three tables through that context, and leaves a prompt with no context unrendered so the call-budget and benchmark readers keep their text. The missing-prompt behavior of #4630 is already in the tree; the project facts of the other four prompts are a follow-up.
Acceptance criteria
Requirement: Jinja2 renders a task prompt with context
load_task_prompt SHALL render a task prompt through one cached Jinja2 SandboxedEnvironment when the caller passes a context.
Scenario: A prompt takes a context value
- WHEN A caller passes a value for a prompt that holds
{{ value }}. - THEN The returned text holds the value in place of the marker.
Requirement: A missing value raises
The environment MUST raise jinja2.UndefinedError when a prompt names a value that the caller's context does not hold.
Scenario: A prompt names an unset value
- WHEN A caller passes a context that holds another value but not
missingto a prompt that holds{{ missing }}. - THEN
load_task_promptraisesjinja2.UndefinedError.
Requirement: A prompt with no variables keeps its text
A prompt with no variables MUST return the text that the current loader returns.
Scenario: Each prompt with no variables
- WHEN A test loads each prompt that holds no
{{ }}marker. - THEN The returned text equals the text that the current loader returns for that prompt.
Requirement: Each used prompt loads with its context
A test MUST load each prompt name that the code uses with the context that its caller passes.
Scenario: Load every used prompt
- WHEN A test loads each prompt name with its caller's context.
- THEN No
UndefinedErroris raised.
Requirement: The implement step prompt gets its tables
The implement step prompt SHALL get its three tables through context.
Scenario: The implement step prompt gets its tables
- WHEN The code builds the implement step prompt for devops-cli.
- THEN The text holds the table rows that the caller passes as context.
Requirement: fill_prompt is removed
The source MUST NOT hold fill_prompt or PROGRAMS_PLACEHOLDER.
Scenario: Search the source
- WHEN A search runs
git grep -n 'fill_prompt\|PROGRAMS_PLACEHOLDER' src. - THEN The search gives no match.
Requirement: The implement step prompt matches today's output
The rendered implement step prompt MUST equal the output of today's fill_prompt for devops-cli.
Scenario: Compare with the recorded output
- WHEN A test renders the implement step prompt for devops-cli with the new loader.
- THEN The text equals the recorded
fill_promptoutput.
Requirement: Prompt version covers the context
stage_plan_record.prompt_version SHALL hash the raw template text and the context values.
Scenario: Two contexts give two versions
- WHEN Two calls hash the same prompt with different context values.
- THEN The two prompt versions differ, and a call with no context does not raise.
Requirement: A prompt read with no context keeps its markers
load_task_prompt MUST return the stripped file text without rendering when the caller passes no context.
Scenario: The call-budget and GitHub prompts keep their markers
- WHEN A test loads
roadmap_stage_tools.mdandbenchmark_embedding_eval_pairs.mdwith no context. - THEN The texts hold
{{plan_calls_advised}}and${{ github.workflow }}-${{ github.ref }}, and noUndefinedErroris raised.
Requirement: No new template dependency
The change MUST NOT add a template dependency, and Jinja2 stays at version 3.1.6.
Scenario: Read the dependency list
- WHEN A test reads the project dependency list.
- THEN Jinja2 3.1.6 is present and no template library is added.
Existing Tool Considered
No alternatives check has run. Jinja2 3.1.6 is pinned in pyproject.toml:23 and is the project's chosen template engine (src/devops_cli/ai/knowledge_base/devops_cli/libraries/pyyaml_jinja2.md:25, :45); src/devops_cli/core/templating.py:43 already builds a cached SandboxedEnvironment with StrictUndefined. Jinja2 covers rendering with strict missing values, but it lacks prompt-aware context validation and prompt version hashing, and it reads GitHub ${{ }} expressions as Jinja, so the loader returns a prompt raw when no context is passed. The wiring adds about 40 lines and 2 tests. The written cost is about 150,000 tokens and 2 hours to build, and about 3,000 tokens a month to keep.
Key questions
- Does the project already render templates through a cached Jinja2
SandboxedEnvironment?: Yes.src/devops_cli/core/templating.py:43defines a cachedtemplate_environment()that returns aSandboxedEnvironmentwithStrictUndefinedatsrc/devops_cli/core/templating.py:57. [sources: src/devops_cli/core/templating.py:43, src/devops_cli/core/templating.py:55, src/devops_cli/core/templating.py:57] - Where does the prompt filling code live today?:
fill_promptis atsrc/devops_cli/roadmap/implement/implement_shell_policy.py:551; it replaces the three{{ }}placeholders atsrc/devops_cli/roadmap/implement/implement_shell_policy.py:240to:242withstr.replaceatsrc/devops_cli/roadmap/implement/implement_shell_policy.py:554to:556. [sources: src/devops_cli/roadmap/implement/implement_shell_policy.py:551, src/devops_cli/roadmap/implement/implement_shell_policy.py:240, src/devops_cli/roadmap/implement/implement_shell_policy.py:554] - Which template engine renders the task prompts?: Jinja2 3.1.6 through a
SandboxedEnvironment. It is pinned atpyproject.toml:23, the project already builds one atsrc/devops_cli/core/templating.py:43, and the knowledge base names it the selected engine. (best practice) [sources: pyproject.toml:23, src/devops_cli/core/templating.py:43, src/devops_cli/ai/knowledge_base/devops_cli/libraries/pyyaml_jinja2.md:25]- Chosen: Jinja2 SandboxedEnvironment. It is already a dependency and the project already uses it with
StrictUndefined. - Rejected: string.Template. It has no conditional blocks and no strict undefined.
- Rejected: LangChain PromptTemplate. It adds a dependency and still uses Jinja2 or f-strings.
- Rejected: pydantic_ai.template. The issue scopes the change to
load_task_promptand its markdown files.
- Chosen: Jinja2 SandboxedEnvironment. It is already a dependency and the project already uses it with
- Where does the Jinja2 environment live?: A module-level cached
SandboxedEnvironmentinsrc/devops_cli/ai/task_loader.py, built liketemplate_environment()but with no loader and no trimming. (best practice) [sources: src/devops_cli/core/templating.py:43, src/devops_cli/ai/task_loader.py:16]- Chosen: module-level environment in task_loader. It renders prompt text and keeps the loader self-contained.
- Rejected: reuse
template_environment(). It loads JSON scaffolding templates through aFileSystemLoaderand trims blocks. - Rejected: a new loader class. The issue says add no new function and no
ChoiceLoader.
- Which settings does the environment use?:
StrictUndefined,keep_trailing_newline, notrim_blocksorlstrip_blocks, and autoescape off. The first two matchtemplate_environment(); no trimming keeps the byte-identical output, and autoescape is off because the prompts are Markdown. (best practice) [sources: src/devops_cli/core/templating.py:49, src/devops_cli/core/templating.py:57, src/devops_cli/core/templating.py:60, src/devops_cli/ai/task_loader.py:25]- Chosen: StrictUndefined, keep_trailing_newline, no trimming, no autoescape. It matches the current loader output and raises on a missing value.
- Rejected: default undefined. A missing value would render empty and hide a defect.
- Rejected: trim_blocks and lstrip_blocks. They would change the text of prompts that render byte-identical today.
- Rejected: autoescape on. Prompts are Markdown text, not HTML.
- Which prompts get context?: The implement step prompt gets its three tables through context in this change. The
stage_change,stage_split,stage_tools_researchandalternativesprompts get their project facts in a follow-up issue: the issue names no fact for them, and they hold no{{ }}marker today. (best practice) [sources: src/devops_cli/roadmap/implement/implement_shell_policy.py:240, src/devops_cli/ai/tasks/roadmap_implement_step.md:49, src/devops_cli/roadmap/implement/implement_step.py:423]- Chosen: implement step now, four prompts in a follow-up. The implement step has named facts and a recorded output; the other four have no fact to pass.
- Rejected: all five prompts now. The issue names no project fact for the other four, so the work cannot be built as written.
- Rejected: no prompt gets context. The implement step tables are the need of the issue.
- Do the personas and benchmark readers change?: No.
src/devops_cli/ai/personas/__init__.py:38andsrc/devops_cli/ai/benchmark/tasks.py:12read plain text. The third benchmark file with GitHub expressions,src/devops_cli/ai/tasks/benchmark_embedding_eval_pairs.md:66, is read throughload_task_promptatsrc/devops_cli/ai/benchmark/embedding_tasks.py:75; it stays raw because the caller passes no context. (best practice) [sources: src/devops_cli/ai/personas/init.py:38, src/devops_cli/ai/benchmark/tasks.py:12, src/devops_cli/ai/benchmark/embedding_tasks.py:75, src/devops_cli/ai/tasks/benchmark_embedding_eval_pairs.md:66]- Chosen: keep them plain text or raw. The GitHub
${{ }}expressions would be read as Jinja. - Rejected: render them through Jinja2. It would break the three benchmark files that hold GitHub expressions.
- Chosen: keep them plain text or raw. The GitHub
- What does
stage_plan_record.prompt_versionhash?: The raw template text plus the context values. Today it hashes the texts thatload_task_promptreturns atsrc/devops_cli/roadmap/stage/stage_plan_record.py:195; with no context the loader returns the stripped raw template atsrc/devops_cli/ai/task_loader.py:25, so the hash adds the context values and does not raise. (best practice) [sources: src/devops_cli/roadmap/stage/stage_plan_record.py:186, src/devops_cli/roadmap/stage/stage_plan_record.py:195, src/devops_cli/ai/task_loader.py:25]- Chosen: hash the raw template text and the context values. It needs no render, so a call with no context does not raise, and a context change gives a new version.
- Rejected: hash the rendered text. The render can raise and changes with the context.
- Rejected: hash the template text only. Two different contexts would share a version.
- Does
load_task_promptrender a prompt when the caller passes no context?: No. With no context it returns the stripped file text. The call-budget prompts atsrc/devops_cli/ai/tasks/roadmap_stage_tools.md:17andsrc/devops_cli/ai/tasks/roadmap_stage_verify_tools.md:7, the embedding eval pairs atsrc/devops_cli/ai/benchmark/embedding_tasks.py:75, and the peer grader's single-brace markers atsrc/devops_cli/ai/benchmark/runner.py:634keep working; a caller that passes a context getsStrictUndefined. (best practice) [sources: src/devops_cli/roadmap/stage/stage_tools.py:91, src/devops_cli/roadmap/stage/stage_tools.py:96, src/devops_cli/ai/tasks/roadmap_stage_tools.md:17, src/devops_cli/ai/benchmark/embedding_tasks.py:75, src/devops_cli/ai/benchmark/runner.py:634]- Chosen: render only when the caller passes a context. It keeps the call-budget and benchmark readers working and matches the issue's 'a call with no context does not raise'.
- Rejected: always render and add a raw read. It changes more call sites and adds a parameter that the issue does not ask for.
- Rejected: render by a list of prompt names. A name list duplicates the loader and drifts from the call sites.
- Is refactor(ai): delete orphan prompts and the prompt fallbacks #4630 delivered?: Yes.
load_task_promptraisesTaskPromptNotFoundErroratsrc/devops_cli/ai/task_loader.py:23, and the delivered spec isopenspec/specs/ai-task-prompts/spec.md:9. The change therefore needs no open dependency. [sources: src/devops_cli/ai/task_loader.py:23, openspec/specs/ai-task-prompts/spec.md:9, openspec/changes/archive/2026-11-11-4630-delete-orphan-prompts-and-the-prompt/proposal.md:11]
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Alternatives check of 2026-11-17: in-use.
The repository already uses this tool.
Tool: Jinja2 (https://pypi.org/project/Jinja2), BSD License, last activity 2025-03-05, not maintained.
Activity
dan-petty commentedon Nov 11, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
featprefix of the title gives the type.(ai)scope of the title gives the scope.It improves maintainability of 37 prompt call sites but does not block users or fix a defect.It replaces four fragile string methods with one testable renderer and removes fill_prompt.The body states about 40 lines, 1 test, and 2 hours of work.Both use Jinja2 SandboxedEnvironment, but #325 targets manifest and Dockerfile rendering while the candidate targets AI task prompt rendering in task_loader.py.devops-cli-service commentedon Nov 14, 2026
Status set to Ready at 0410772 (see proposed design in issue body).
Moved to new items: #5638.
devops-cli-service commentedon Nov 17, 2026
Alternatives check: in-use
Reason: The issue's need is to render task prompts with project values through a cached template engine with strict missing-value errors, and Jinja2's SandboxedEnvironment with StrictUndefined is exactly that engine: the searches confirmed Jinja2 is an open, maintained project (3.1.6, BSD-3-Clause) that the repository already depends on and already builds a sandboxed environment from. Its conditional blocks and strict undefined cover the rendering need, so the remaining work (cached loader, version hashing, raw reads) is project wiring rather than a missing tool.
The repository already uses this tool.
Tool: Jinja2 (https://pypi.org/project/Jinja2)
Covers:
{{ value }}markers and conditional blocksUndefinedErroron a missing valueLacks:
${{ }}expressions as Jinja, so the loader must return a prompt raw when no context is passedTools considered:
Searches run:
Sources:
Checked on 2026-11-17. A person decides what this means for the item. The check changes no label and closes no issue.
devops-cli-service commentedon Nov 17, 2026
Released in v0.173.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.173.0
devops-cli-service commentedon Nov 17, 2026
Live since 2026-11-17 14:05 UTC