Trace Prompt System¶
Prompt text is externalized, deterministic, and traceable.
1) Core Contract¶
- Task modules must not hardcode user-facing prompt text.
- Active source-layout scenes use prompt bundles under
src/trace_tasks/resources/prompts/<domain>/<scene_id>/<bundle_id>.json. - Composition layers are:
- scene,
- task,
- optional query,
- output mode (
answer_only,answer_and_annotation). - Selection is deterministic from seed namespaces.
- Required template lists contain exactly 5 high-quality variants unless the schema declares an approved exception.
- All active tasks must provide task-specific JSON-format guidance in both output modes:
answer_onlyuses{"answer": ...}answer_and_annotationuses{"answer": ..., "annotation": ...}- Output-mode instructions should keep task-specific
answer_hint,annotation_hint, and JSON examples. Consumers may add a generic final JSON-object instruction without changing task semantics. - For named colors, include the canonical hex code in the prompt-facing color
label using
<color_name> [#RRGGBB]. - If the query layer already contains the full question, the task layer may be
empty only when the bundle declares
allow_empty_task_templates: true.
2) Bundle Schema¶
Required fields:
bundle_idschema_versionscene_templatestask_templatesanswer_or_annotation_templatesrequired_slots_by_key
Optional fields:
query_templatesallow_empty_task_templates
Required slots should be declared at the narrowest layer that needs them:
scene:<scene_key>for scene-wide visual framing slots;task:<task_key>for objective-level slots;query:<query_key>for branch-specific wording slots;- output-mode keys for answer/annotation examples and hints.
3) Metadata Requirements¶
Trace query_spec.prompt_variant should include:
- bundle id and layer keys;
- selected variant indices;
- query id and query-id count when applicable;
- slot values for declared required slots;
- output-mode key/index;
- prompt asset version when available.
Train records should store the active prompt and generated prompt_variants
when both output modes are materialized.
4) Shared Implementation¶
src/trace_tasks/core/prompts/assets.py— bundle loading/cache.src/trace_tasks/core/prompts/schema.py— schema validation.src/trace_tasks/core/prompts/select.py— deterministic variant selection.src/trace_tasks/core/prompts/render.py— strict rendering and metadata.src/trace_tasks/tasks/shared/prompt_variants.py— task-level dual-mode orchestration.src/trace_tasks/tasks/shared/prompt_json_example.py— deterministic JSON-example helpers.
5) Prompt Quality Policy¶
- Keep stems natural and image-focused.
- Scene layer describes the visible scaffold only. Do not include taxonomy, source, or construction-category labels that are not needed to solve the task, such as calling a prompt scaffold "special", "synthetic", "procedural", "unlettered", or naming an internal scene family when the concrete visible object labels already carry the needed information.
- Task layer states the operation only when needed.
- The query layer owns the actual question; user-facing wording should come from prompt templates.
- Output-mode layer owns field hints and JSON examples.
- Avoid repeating broad nouns such as image, chart, table, diagram, board, question, or answer across adjacent layers.
- Template examples show valid output format for the active answer and annotation contract, not the sampled instance's actual answer. The example annotation should be an answer-verification witness for the task family, not a full derivation/proof trace.
- Template examples must be internally coherent. If the example answer is a count and annotation is the counted witness collection, the example annotation cardinality must match the example answer. Scalar examples must use scalar shapes, not one-item sets.
- Annotation examples and hints must use final image pixel coordinates, not grid indices, scene coordinates, data values, or normalized coordinates.
- Use
annotationterminology in prompts. - Prefer direct operand-bound questions over indirect scene-mechanics wording. When the task asks for a total, comparison, or selection over named operands, the query template should name those operands directly rather than making the model infer the requested operation from verbose visual descriptions.
6) Source Of Truth¶
Do not maintain exhaustive task-to-bundle maps in this document. They drift.
Use:
- config references under
src/trace_tasks/resources/configs/domains/; - prompt assets under
src/trace_tasks/resources/prompts/; - runtime prompt metadata in
query_spec.prompt_variant; - generated task inventory in
docs/ACTIVE_TASK_INVENTORY.md; - task-level contracts in
docs/tasks/.
Validate prompt bundles and rendering with:
pytest -q tests/test_prompt_system.py