Skip to content

feat(ai): standardize result envelope across AI endpoints (#609)#684

Open
teethaking wants to merge 2 commits into
Pulsefy:mainfrom
teethaking:feature/609-standardize-result-envelope
Open

feat(ai): standardize result envelope across AI endpoints (#609)#684
teethaking wants to merge 2 commits into
Pulsefy:mainfrom
teethaking:feature/609-standardize-result-envelope

Conversation

@teethaking

Copy link
Copy Markdown

Add ResultEnvelope[T] to schemas/common.py with fields:
result, confidence, reasons, anchor_metadata, trace_id

Updated endpoints: OCR, fraud, humanitarian, anonymize, proof-of-life

  • confidence derived from field scores (OCR), portfolio cleanliness (fraud), LLM output (humanitarian), null for deterministic (anonymize)
  • reasons populated from flagged claims / LLM reasoning / PII count
  • trace_id sourced from existing correlation_id_var context var
  • anchor_metadata passed through unchanged

Legacy /ai/* routes in main.py are untouched (no breaking changes) Added tests/test_result_envelope.py; updated existing test suites
Closes #609

Add ResultEnvelope[T] to schemas/common.py with fields:
  result, confidence, reasons, anchor_metadata, trace_id

Updated endpoints: OCR, fraud, humanitarian, anonymize, proof-of-life
- confidence derived from field scores (OCR), portfolio cleanliness (fraud),
  LLM output (humanitarian), null for deterministic (anonymize)
- reasons populated from flagged claims / LLM reasoning / PII count
- trace_id sourced from existing correlation_id_var context var
- anchor_metadata passed through unchanged

Legacy /ai/* routes in main.py are untouched (no breaking changes)
Added tests/test_result_envelope.py; updated existing test suites
@vercel

vercel Bot commented Jun 29, 2026

Copy link
Copy Markdown

@teethaking is attempting to deploy a commit to the Cedarich's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Jun 29, 2026

Copy link
Copy Markdown

@teethaking Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Cedarich

Copy link
Copy Markdown
Contributor

@teethaking fix workfow

)

- test_main.py: update proof_of_life, anonymize, humanitarian tests to
  assert on ResultEnvelope fields (result/confidence) instead of old
  flat shape; humanitarian failure now expects 500 error envelope
- test_versioned_routes.py: mock run_ocr_from_bytes in v1 OCR tests to
  avoid Tesseract dependency in CI; fix humanitarian failure test to use
  raise_server_exceptions=False client; update parity tests to expect
  ResultEnvelope from both v1 and legacy redirect paths
- test_routes.py: revert OCR processing_time assertion to legacy shape
  (legacy /ai/ocr route unchanged)
- test_result_envelope.py: fix anchor_metadata passthrough test to
  include anchor in mock return value
- test_fraud_detection.py: already fixed in prior commit (result list)
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

2 participants