feat: Add a Python Callout implementation for the Prompt Amendment / Insertion - #356
Open
victorwoli wants to merge 7 commits into
Open
feat: Add a Python Callout implementation for the Prompt Amendment / Insertion#356victorwoli wants to merge 7 commits into
victorwoli wants to merge 7 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prompt-Amender: ext_proc callout for centralized LLM prompt governance
Adds
prompt_amender, anext_proccallout that matches requests by caller identity/host/path against a hot-reloadable YAML ruleset and mutatessystemInstructionin flight — injecting safety guardrails and context without client code changes or redeploys.Highlights
Header-phase glob matching
(spiffe://``/principalSet://normalized);mode_overrideskips body buffering for unmatched traffic.Body-phase mutation (
prepend/append/replace/template, sandboxed Jinja2, compiled once); accepts bothsystemInstructionandsystem_instruction, inserting one if missing.Correctly handles Envoy's streamed body delivery — non-final chunks withheld via
clear_bodyrather than naively accumulated, so multi-chunk requests aren't corrupted; failures reconstruct the original body (fail-open) or reject (fail-closed).Hot-reload from GCS/git with atomic swap and validation-reject.
Structured JSON logs (no raw prompt text) and real OTEL metrics/tracing.
Included: callout code, Terraform (with
strip_client_spiffe_iddefaultingtrue— identity headers only trustworthy behind a real gateway), Dockerfile, README, and 38 unit tests (no gRPC/network deps).Follow-up:
callouts/python/requirements-test.txtneedsJinja2==3.1.4added (seerequirements-test-addition.txt) — a shared file outside this PR's diff.