Skip to content

feat(ai-service): standardize result envelope across AI endpoints (#609)#4

Merged
Whiznificent merged 1 commit into
mainfrom
feat/609-standardize-result-envelope
Jun 24, 2026
Merged

feat(ai-service): standardize result envelope across AI endpoints (#609)#4
Whiznificent merged 1 commit into
mainfrom
feat/609-standardize-result-envelope

Conversation

@Whiznificent

Copy link
Copy Markdown
Owner

Add ResultEnvelope base class with result, confidence, reasons, anchor_metadata and trace_id fields. Compose into all v1 response schemas (OCR, fraud, anonymize, humanitarian, proof-of-life) and populate the fields in every endpoint handler.

All envelope fields are Optional so existing callers see no breaking changes. trace_id is auto-generated (UUID4) per request.

  • schemas/envelope.py – new ResultEnvelope Pydantic mixin
  • schemas/ocr.py – OCRResponse extends ResultEnvelope
  • schemas/fraud.py – FraudDetectionResponse extends ResultEnvelope
  • schemas/anonymization.py – AnonymizeResponse extends ResultEnvelope
  • schemas/humanitarian.py – HumanitarianVerificationResponse extends ResultEnvelope
  • api/v1/ocr.py – populate envelope (avg confidence, filename anchor)
  • api/v1/fraud.py – populate envelope (risk-derived confidence, flagged IDs)
  • api/v1/anonymize.py – populate envelope (rule-based, PII count anchor)
  • api/v1/humanitarian.py – populate envelope (verdict confidence, provider anchor)
  • api/v1/proof_of_life.py – populate envelope (confidence passthrough, checks anchor)
  • tests/test_result_envelope.py – schema + endpoint envelope validation tests

closes Pulsefy#609

…lsefy#609)

Add ResultEnvelope base class with result, confidence, reasons,
anchor_metadata and trace_id fields. Compose into all v1 response
schemas (OCR, fraud, anonymize, humanitarian, proof-of-life) and
populate the fields in every endpoint handler.

All envelope fields are Optional so existing callers see no breaking
changes. trace_id is auto-generated (UUID4) per request.

- schemas/envelope.py  – new ResultEnvelope Pydantic mixin
- schemas/ocr.py       – OCRResponse extends ResultEnvelope
- schemas/fraud.py     – FraudDetectionResponse extends ResultEnvelope
- schemas/anonymization.py – AnonymizeResponse extends ResultEnvelope
- schemas/humanitarian.py  – HumanitarianVerificationResponse extends ResultEnvelope
- api/v1/ocr.py        – populate envelope (avg confidence, filename anchor)
- api/v1/fraud.py      – populate envelope (risk-derived confidence, flagged IDs)
- api/v1/anonymize.py  – populate envelope (rule-based, PII count anchor)
- api/v1/humanitarian.py – populate envelope (verdict confidence, provider anchor)
- api/v1/proof_of_life.py – populate envelope (confidence passthrough, checks anchor)
- tests/test_result_envelope.py – schema + endpoint envelope validation tests
@Whiznificent Whiznificent merged commit edb6ba0 into main Jun 24, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Standardize Result Envelope Across AI Endpoints

1 participant