Prompt Locking¶
Prompt integrity locking helps you detect prompt tampering before content is sent to the LLM.
Why this exists¶
Prompt files can be edited accidentally or maliciously. This feature gives you a deterministic check that says: - "These are the prompt files we trust." - "These are the exact hashes we expect."
Mental model¶
prompts.tomlis the manifest (what to track).prompts.lock.jsonis the lock (path → sha256 hash).- Preflight verification checks all tracked prompt files against the lock at execute start.
- Include-time verification checks included prompt bytes before include content is parsed/used.
Schema compatibility¶
prompts.tomlandprompts.lock.jsoncarry internal version checks (version = 1) so Margarita can fail fast on incompatible schema changes.- The lock also pins
algorithm = "sha256"to keep hashing deterministic and prevent silent verification drift.
One-time setup¶
margarita prompts init
margarita prompts lock
margarita prompts check
This creates:
- prompts.toml
- prompts.lock.json
Day-to-day workflow¶
- Edit a tracked prompt file under
prompts/(.mg/.mgx). - Run
margarita prompts check(it should fail until the lock is updated). - Run
margarita prompts lockto regenerate hashes. - Run
margarita prompts checkagain (should pass). - Commit both the prompt changes and
prompts.lock.json.
Runtime behavior¶
During run, verification is auto-enabled when prompts.toml exists.
- No
prompts.toml: execution continues (feature is opt-in). prompts.tomlexists but lock missing: execution fails (fail-closed).- Any tracked file hash mismatch: execution fails.
- Include outside trusted
prompts/root: - blocked by default
- allowed only with
--allow-unverified - Missing include file: execution fails.
Execute flag behavior¶
--verify-prompts: force verification on (fails ifprompts.tomlorprompts.lock.jsonis invalid/missing).--no-verify-prompts: force verification off (skip manifest/lock checks for this run).--allow-unverified: permits includes outside the trustedprompts/root with a warning.
How they interact:
- Default (run with no verify flag): auto mode — verify only when prompts.toml exists.
- --allow-unverified only matters when verification is enabled.
Security notes¶
- This is tamper-evident integrity and change control, not a complete security boundary.
- Trust in
prompts.lock.jsoncomes from your review process (PR review, protected branches, CI checks). - Recommended CI gate: run
margarita prompts checkon pull requests.