Part XVI — Engineering Implementation and Production Infrastructure
Chapter 84. The Prompt Compiler: From Creative Contract to Vendor Call#
In this chapter
A production system should not have every operator assembling prompts by hand. A prompt is an executable artifact compiled from the episode pack, identity contracts, state snapshots, shot requirements and a vendor adapter. Creative facts live upstream; the prompt version's only job is translating them into a form the current model understands.
84.1 Compiling creative intent into a constraint system#
Five input layers.
The first layer is the task objective and acceptance. The second is locked facts. The third is current state. The fourth is visual, audio or performance references. The fifth is vendor control parameters. The layers carry priority: a lower layer cannot override a higher one.
prompt_source:
task: the folder passes from Lin Xia's left hand to Gu Zhou's right
facts: [folder_red, holder_in_lin, holder_out_gu]
identity: [lin_v03, gu_v04]
state: [wardrobe_state_06, boardroom_bluehour_v04]
camera: [zone_a, 50mm, subtle_push]
acceptance: [dual_grip_visible, no_mirror, identity_pass]
provider_adapter: video_b_2026_06
Positive constraints, negative constraints, and invariants.
Positive constraints describe the states that must appear. Negative constraints list the high-probability disasters. Invariants declare what may never change under any circumstances. A negative list should not be stuffed with dozens of generic words; it contains only this shot's risks — the folder must not duplicate, the mole must not switch sides, the ending holder must not be wrong.
Abstract intent is translated into observable behavior. "Calm and powerful" compiles into sitting before speaking, not raising the volume, not looking at the document, and landing the sentence ending. The model can still perform inside the envelope without being controlled pixel by pixel.
84.2 Reference selection, context compression, and vendor adapters#
The reference selector.
References are retrieved by shot angle, expression, lighting and visible body parts, rather than sending the same frontal portrait on every call. Profile shots prioritize a profile identity anchor; hand actions add cuff and prop references; multi-person shots receive a slot diagram. Too many references produce conflict, so the selector must be able to explain why each image was included.
reference_selection:
selected:
- {asset: lin_3q_v03, reason: face_angle_match, weight_role: identity_primary}
- {asset: folder_dual_grip_v02, reason: action_peak, weight_role: state_primary}
- {asset: boardroom_zone_a_v05, reason: spatial_match, weight_role: environment}
excluded:
- {asset: lin_front_v03, reason: angle_conflict}
- {asset: old_wardrobe_v01, reason: lifecycle_retired}
Context compression and provenance.
The compiler includes only the shot's direct dependencies. Season secrets, future injuries and unrelated characters stay
out, so the model cannot leak them early. Compressed summaries retain a source_ref and a checksum, so a dispute can
return to the original fact.
When two authoritative sources conflict — the shot list saying left hand and the state table saying right — the compiler must fail and produce a conflict report. It may not choose by recency or text order.
Vendor adapters.
A unified semantic layer converts into each service's fields, reference counts, durations and limits. The adapter also handles unit conversion, defaults, unsupported capabilities and output normalization. When a vendor does not support an end frame, it returns a capability mismatch rather than dropping the constraint and calling anyway.
Adapter versions bind to generated assets. Updating an adapter can change prompt order and parameters, so regression runs even when the model version is unchanged.
84.3 Manifests, parsing, and regression control#
The prompt manifest.
prompt_manifest:
prompt_run_id: prun_e001_015_a04
compiler_version: 2.7.0
template_version: shot_handoff_4.2.1
adapter_version: video_b_1.8.0
source_checksums:
episode_pack: sha256:aaa
identity_bundle: sha256:bbb
state_packet: sha256:ccc
rendered_prompt_checksum: sha256:ddd
assumptions: []
excluded_context: [future_secret, retired_wardrobe]
The manifest makes a result explicable; it does not promise vendor determinism. The minimum standard of reproducibility is knowing the inputs and the compilation process — not a promise of identical pixels.
Output parsing and contamination isolation.
Text explanations and metadata returned by a model are treated as non-authoritative. The parser validates files, duration, format and schema. A model asserting that continuity passed cannot write an approved state. Candidates enter quarantine and are promoted only through independent evaluation and a human gate.
If model output proposes a new story fact, it can only be a candidate suggestion; it does not enter the fact registry. The generation layer has no authority to rewrite the story.
Prompt regression testing.
The golden set covers identity, action, space, text and safety boundaries. Tests check whether structured output is valid, whether required fields are present, whether retired assets are excluded, whether conflicts block, and whether tokens exceed limits. Image results are reviewed statistically and by humans; pixel snapshots are not required.
Stage the rollout at ten percent of tasks and compare schema failures, human rejections, cost per approved second and error types. Any escaped blocker rolls back immediately.
84.4 Diagnosis and compile-diff review#
Fault tree.
Prompts growing longer while results worsen: context was not trimmed by dependency. A character knowing a future secret: knowledge state isolation failed. References fighting each other: the selector lacks angle and lifecycle rules. Constraints lost after a vendor change: the adapter de-escalated silently. Results contaminating the fact library: candidate output and authoritative writes are not separated.
SOP, checklist and deliverables.
Define the unified semantic schema. Implement provenance resolution. Select the minimum references. Check for conflicts. Compile observable behavior. Apply the vendor adapter. Store the manifest. Quarantine outputs. Run regression and staged rollout. Monitor quality and cost.
- A prompt can be regenerated from the upstream contracts.
- Every context section has a source and an authority level.
- Unsupported capabilities fail rather than being ignored.
- Model output cannot write facts or approval states directly.
- The compiler and the adapter carry independent versions.
Exercise: implement a compiler from one shot semantic packet into two vendor formats, delivering prompt_schema.json,
reference_selector.yaml, adapters/, manifests/, regression_cases/ and canary_report.md.
Compile-diff review.
Any prompt template or adapter upgrade produces a semantic diff rather than a plain text comparison. The review answers: which facts were added, which constraints removed, why reference selection changed, how unsupported capabilities are handled, and how the token budget shifted. Whitespace and sentence order can be collapsed; identity, action and rights changes must be highlighted.
Rehearse with the handoff shot: a new adapter version permits only two references, so the selector drops the boardroom wide. The system must not submit silently. It surfaces the missing spatial anchor risk and offers three routes — compile the spatial information into text, composite an approved reference board, or route to a capability supporting three references. Once a human decides, the reason enters the manifest, so a later failure remains traceable.
Acceptance for the compiler includes: identical authoritative inputs produce identical semantic output; conflicting inputs always block; retired assets cannot enter; a vendor capability gap never disappears silently; and any generated result can be traced back to its complete provenance.
Before release, spot-check with a human-readable view as well, so structurally valid output cannot be semantically wrong.
Archive the spot-check results.
A note on sources#
Prompt engineering advice ages with models. What transfers is treating the prompt as a compiled artifact over versioned contracts, so the creative facts survive a change of vendor, adapter or template.