procurement-ingest/lambdas/wo/email_processor
amoussa1229 23a67f7254 fix: add fail-closed validation gate and XML-delimited prompt on ai_fallback path
The ai_fallback parse path applied no validation gate to raw Bedrock/LLM
output before DynamoDB writes, and the extraction prompt concatenated the
untrusted email body directly with no instructions-vs-data delimiter. A
DKIM-passing attacker could prompt-inject arbitrary field values into the
work-order store.

Changes:
- wrap untrusted email in \<email\> XML block with prompt instructing the
  model to treat its contents as data only
- add validate_ai_fallback() in template_parser that enforces the same
  contract keys, enums, and patterns as the template path before any write
- call validate_ai_fallback() in handler() dispatch; emit an
  ai_fallback_rejected EMF metric on failure and skip the record
- add 17 unit tests covering every gate rule and two end-to-end dispatch
  tests (injected email_type, injected status)

Refs #101
2026-07-16 19:08:29 +00:00
..
tests fix: add fail-closed validation gate and XML-delimited prompt on ai_fallback path 2026-07-16 19:08:29 +00:00
__init__.py Merge workorder-ingest into unified procurement repo (#22) 2026-05-12 15:21:06 -04:00
handler.py fix: add fail-closed validation gate and XML-delimited prompt on ai_fallback path 2026-07-16 19:08:29 +00:00
requirements.txt feat: template-first WO parser + Bedrock fallback, PO Bedrock switch (#99) 2026-07-16 12:45:11 -04:00
ses_auth.py fix(ses_auth): harden comment stripping and alarm evaluation window (#103) 2026-07-16 19:00:40 +00:00
template_parser.py fix: add fail-closed validation gate and XML-delimited prompt on ai_fallback path 2026-07-16 19:08:29 +00:00