เกตเวย์ AI ที่คัดกรองแต่ละคำขอเพื่อหาความพยายามที่จะเขียนทับคำสั่งของโมเดล
ผู้
Feature ที่core/prompt-injection-shield สิ่ง
พื้นที่
สิ่งที่ตัวอย่างนี้บิลด์
| อินสแตนซ์ | Component ของ | สิ่ง |
|---|---|---|
router | core/gateway/litellm | เกตเวย์ AI: alias เดียวassistant เขียน |
guard | core/security/nemo-guardrails | เซิร์ฟเวอร์ |
detector | core/security/trustyai-huggingface-detector | บริการ |
เส้นuses สองguard ของdetector ของ guard ไปshield ซึ่งsensitivity: standard และ upstream_key ซึ่ง
ร่างตัวอย่าง
คุณ
เขียน
aggrega draft --example ai-gateway-prompt-injection-shieldจาก
cd ai-gateway-prompt-injection-shieldบิลด์
aggrega build --release release.yaml --auto-pullRelease ต้อง
aggrega pull --release release.yaml # resolve once, then build with no flagaggrega build --release release.yaml --auto-pull # or resolve during the buildพื้นที่.aggrega-config.yaml ระบุ realization ของ shield รันpipeline-step/litellm-gateway-config ซึ่งdefault_registry ระบุ คือ hub.aggrega.ai
บิลด์<workspace> แทน
[… omitted: a line reporting on the gateway configuration step's plugin, a warning that the upstream_key credential's declared-sensitive origin reaches the target with no per-key sensitivity marking, because the realization maps it through a valuesMapping, the resolution's summary, a notice that core/referenced-secret declares origin in both of its pillars, and a total build time, which differs per run]Build completed: 10 files written to <workspace>/distRelease ระบุinfra.image ของrelease.yaml เป็น
กับผู้ช่วย AI
ผู้
ใช้เฉพาะเครื่องมือของ Aggrega และอย่าสร้างโฟลเดอร์เอง หากโฟลเดอร์ Workspace ยังไม่มีโฟลเดอร์ `ai-gateway-prompt-injection-shield` เรียกเครื่องมือ `draft` หนึ่งครั้งโดยตั้ง `example` เป็น `ai-gateway-prompt-injection-shield` และไม่ใส่ `dir`: เครื่องมือจะเขียนตัวอย่างลงในโฟลเดอร์ `ai-gateway-prompt-injection-shield` ใหม่ จากนั้นเรียกเครื่องมือ `build` โดยตั้ง `workspace_root` เป็น `ai-gateway-prompt-injection-shield` ตั้ง `release` เป็น `release.yaml` ตั้ง `auto_pull` เป็น true และตั้ง `write` เป็น true แจ้งฉันว่าบิลด์เขียนไฟล์ใดบ้าง ไฟล์เหล่านั้นอยู่ใต้ `ai-gateway-prompt-injection-shield/dist/`ทรีที่เรนเดอร์
dist/helm/├── detector-default-service.yaml├── detector-deployment.yaml├── guard--upstream-zukey--guard-secret-guard-upstream-key.yaml├── guard-default-service.yaml├── guard-deployment.yaml├── guard/│ └── nemo-guardrails-config.configmap.yaml├── router-default-service.yaml├── router-deployment.yaml└── router/ ├── litellm-gateway-config/ │ └── configmap.yaml └── request-guard/ └── request-guard.yamlshield ไม่
เส้นทางตามที่เกตเวย์อ่าน
เนื้อหาconfig.yaml ของ dist/helm/router/litellm-gateway-config/configmap.yaml:
model_list: - model_name: assistant litellm_params: model: openai/gpt-4o-mini api_base: "http://guard-default:8000/v1" api_key: "the-guard-holds-the-upstream-credential"litellm_settings: callbacks: - /etc/litellm-request-guard/request_field_filter.filtercallback_settings: request_field_filter.router-shield: policies: - reason: "sends every model request through a prompt-injection guard, which checks chat completions only" served_request_types: - acompletionมี
ทุก alias ถูกapi_base คือguard คำขอassistant จึงgpt-4o-mini และ guard ส่งrelease.yaml ระบุupstream_endpoint ลบ shield ออก แล้วapi_base ตรงvalues.models ของmodels: รายการ
เกตเวย์upstream_key ของ guard เฮดเดอร์ Authorization ของ
ให้
This gateway sends every model request through a prompt-injection guard, which checks chat completions only, and it does not serve embeddings requests while it does, so the request was not forwarded. It serves chat completions requests.guard ทำอะไร
การconfig.yaml ของ dist/helm/guard/nemo-guardrails-config.configmap.yaml ตั้งแต่
rails: config: hf_classifier: prompt_injection: engine: fms model: "protectai/deberta-v3-base-prompt-injection-v2" base_url: "http://detector-default:8000" threshold: 0.5 blocked_labels: ["INJECTION"] input: flows: - hf classifier check input $classifier=prompt_injectionสำหรับINJECTION ที่ 0.5 ขึ้น
ผู้rails.co ที่guardrails ซึ่งextra_body
สิ่งที่การนำเข้าไม่ทำ
- shield พลาด
บาง คำการ โจมตี และ ปฏิเสธ บาง คำขอ ที่ ชอบ ธรรม ตัดสิน คือ คะแนน ของ ตัว จำแนก เทียบ กับ เกณฑ์ ความ พยายาม ที่ เขียน ใหม่ เขียน เป็น ภาษา อื่น เข้า รหัส หรือ สะกด ใหม่ อาจ ได้ คะแนน ต่ำ และ ผ่าน ไป ได้ คำขอ ปกติ อาจ ได้ คะแนน สูง และ ถูก ปฏิเสธ - shield อ่าน
เฉพาะ ความข้อความ ล่าสุด ของ ผู้ ใช้ พยายาม ที่ วาง ไว้ ใน ข้อความ ระบบ เทิร์ นก่อน หน้า หรือ ผล จาก เครื่อง มือ ไป ถึง โมเดล โดย ไม่ ถูก อ่าน - shield ไม่
ตัดสิน อาร์กิวเมนต์คำ ตอบ ของ โมเดล ของ การ เรียก เครื่อง มือ และ รูปภาพ - shield ครอบคลุม
เฉพาะ เวิร์กโหลดทราฟฟิก ที่ ผ่าน เกตเวย์ ที่ เรียก ที่ อยู่ ของ โมเดล โดยตรง เลี่ยง shield ไป guard และ ตัว ตรวจ จับ ไม่ ยืนยัน ตัวผู้ เรียก ใด Services ของ ทั้ง สอง จึง เป็น ที่ อยู่ สำหรับ ส่วน ประกอบ ที่ เรียก ใช้ ไม่ใช่ ที่ อยู่ ที่ จะ เผย แพร่
ความไว
guard ใช้ standard และ strict เป็น0.5 และ 0.001 ตัวเลข0.5 guard ปฏิเสธ0.001 guard ปฏิเสธ0.008 ด้วย และ
เกณฑ์strict จึงsensitivity: strict บนthreshold: 0.001 ใน values ของ guard realization ตรวจ
อะไรที่ทำให้บิลด์หยุด
แต่ละ
-
ความ
ไว ตั้งกับ เกณฑ์ ของ guard ไม่ ตรง กัน sensitivity: strictและปล่อย guard ไว้ ที่ ค่า เริ่ม ต้น: [… omitted: a line reporting on the gateway configuration step's plugin, what resolving the lockfile prints, the same halt among it, and a notice that core/referenced-secret declares origin in both of its pillars][CATALOG_ERROR E0010] instance routernode "router": pipeline step failed[… omitted: the step, the template position and the template's own source]error calling fail: core/prompt-injection-shield attachment "shield" on "router" asks for sensitivity strict, which this realization runs as the guard's threshold 0.001, but the guard "guard" runs at 0.5; set values.threshold of "guard" to 0.001 -
ไม่มี guard ที่
เชื่อม ลบโยง บล็อก usesของเกตเวย์ ซึ่ง มี เพียง เส้น เชื่อม guardและบิลด์ หยุด ก่อน เรนเดอร์ สิ่ง ใด โดย ระบุ ชื่อ ซ็อกเก็ต: [… omitted: a line reporting on the gateway configuration step's plugin, what resolving the lockfile prints, the same halt among it, and a notice that core/referenced-secret declares origin in both of its pillars][CATALOG_ERROR E0033]Recipe/FeatureRecipe assertionscaused by: FeatureRecipe "prompt-injection-shield-litellm" instance "router" assertion "guard_is_wired": [… omitted: the template position and the assertion's own source]: error calling fail: assertion failed: core/prompt-injection-shield attachment "shield" on "router" needs a guard to send the gateway's model requests through, but nothing is wired to its guard socket; wire a core/security/nemo-guardrails to the guard socket of "router" -
โมเดล
ที่ เชื่อม โยง กับ ซ็อกเก็ต modelsของเกตเวย์ รายการของ โมเดล นั้น จะ ถูก ส่ง ไป ยัง ปลาย ทาง ของ โมเดล นั้น เอง ด้วย คีย์ ของ การ เชื่อม ต่อ นั้น เอง โดย ข้าม guard เชื่อม โยง core/ai-model/openaiกับซ็อกเก็ต ใน ชื่อ fastพร้อมข้อมูล รับรอง บน การ เชื่อม ต่อ เคียง กับ alias ที่ เขียน เอง โดย ตั้ง values.model: assistantเพราะเกตเวย์ จะ ให้ บริการ สอง alias และ เผย แพร่ เพียง alias เดียว และ ระบุ fastใน Release พร้อม Recipe ของโมเดล นั้น ใน Manifest แล้ว บิลด์ จะ หยุด ก่อน เรนเดอร์ สิ่ง ใด โดย ระบุ ชื่อ การ เชื่อม ต่อ: [… omitted: a line reporting on the gateway configuration step's plugin, what resolving the lockfile prints, the same halt among it, and a notice that core/referenced-secret declares origin in both of its pillars][CATALOG_ERROR E0033]Recipe/FeatureRecipe assertionscaused by: FeatureRecipe "prompt-injection-shield-litellm" instance "router" assertion "no_wired_models": [… omitted: the template position and the assertion's own source]: error calling fail: assertion failed: core/prompt-injection-shield attachment "shield" on "router" sends every model request through the guard, which forwards it to its own upstream with its own credential, but the models socket of "router" holds fast, each sent to its own model's endpoint with its own connection's credential, past the guard; remove those connections and reach that model through the guard's upstream, or remove the shield attachment -
ข้อมูล
รับรอง บน สล็อต provider_keyของเกตเวย์ จะถูก แสดง ต่อ guard และ ไม่ ต่อ โมเดล ใด บิลด์ ระบุ สล็อต upstream_keyของ guard แทน -
guard อื่น ซ็อกเก็ต
ยอมรับ ส่วน ประกอบ ใด ก็ตาม ที่ prompt guard ของ ส่วน ประกอบ นั้น เป็น ของ ตัว จำแนก ที่ ผ่าน การ ฝึก และ realization หยุด กับ ทุก ตัว ยกเว้น core/security/nemo-guardrailsซึ่งเป็น ตัว ที่ วัด ความ ไว ทั้ง สอง ระดับ ไว้ และ หยุด เมื่อ มี guard ตัว ที่ สอง เชื่อม โยง กับ ซ็อกเก็ต ด้วย -
เป้า
หมาย ที่ ไม่ ได้ เขียน เป็น openai/<model>ซึ่งเกตเวย์ จะ ส่ง ไป ยัง guard ผ่าน API อื่น -
core/semantic-cachingบนเกตเวย์ แคชเดียวกัน สร้าง เอมเบดดิง ของ แต่ละ พรอมต์ ผ่าน alias หนึ่ง ของ แมป ซึ่ง จะ ถูก ส่ง ไป ยัง guard ซึ่ง ไม่ ตอบ คำขอ embeddings แคช จึง ไม่ แคช สิ่ง ใด -
shield ตัว
ที่ สอง บน เกตเวย์
เมื่อเข้าถึง guard หรือตัวตรวจจับไม่ได้
คำขอ
ตำแหน่งที่คอมไพเลอร์ไม่ตีความ
คอมไพเลอร์
การปรับแต่งตัวอย่างนี้
- เข้ม
งวด ตั้งขึ้น sensitivity: strictบนการ แนบ และ threshold: 0.001บน guard พร้อมกัน - โมเดล
ที่ ชี้คุณ รัน เอง upstream_endpointของ guard ไปที่ ปลาย ทาง ของ เซิร์ฟเวอร์ โมเดล ซึ่ง core/ai-model/vllmเผยแพร่ ไว้ และ เขียน เป้า หมาย ของ alias เป็น openai/<the name that server serves> - ใช้
เกตเวย์ NGINX แทน core/gateway/nginxประกาศซ็อกเก็ต guardเดียวกัน และprompt-injection-shield-nginxบน helm และ compose ชี้ location เดียวของ เกตเวย์ ไป ที่ guard แทน upstream เดิม ตั้ง upstream_endpointของ guard เป็นโมเดล ที่ ซ็อกเก็ต upstreamของเกตเวย์ ระบุ ทุก คำขอ บน location นั้น ไป ที่ guard ซึ่ง ให้ บริการ chat completions และ ตอบ เส้น ทาง โมเดล อื่น ด้วย 404