Skip to main content
This guide is the implementation contract for the MVP Analysis Engine. The MVP delivers document requirements, secure upload, per-document analysis, deterministic operation scoring, a persisted Decision Pack, signed redacted webhooks, and mandatory human review. The MVP does not deliver automatic operation approval, automatic regulatory submission, legal fine-tuning, autonomous sanctions/PEP decisions, or n8n as a system of record.

Source of truth

n8n must not store final decisions, raw documents, active policy, approved corpus, or primary audit history. The API/worker validates n8n JSON before persisting business state.

Railway workflows

The operation decision workflow receives operationFacts, approvedRequirements, approvedRequirementAssessment, documents, documentAnalyses, activePolicy, regulatoryCorpusVersion, rulesVersion, modelProfile, and traceContext. It returns the closed contract-v2 Decision Pack schema and echoes the exact input snapshot hash. If a conclusion lacks a source, it returns a not-determined or review-required outcome with an absence reason; it must not invent a regulatory conclusion or score through missing evidence.

State machine

The repo keeps backward-compatible public states and maps the closure spec as follows: Allowed MVP transitions: No transition can approve, reject, or request changes without ManualReviewService.

API contract

Minimum endpoints: Existing endpoints remain supported for compatibility: /upload-sessions, /documents, /analysis-results, /document-requirements, and /webhooks/:webhookId/test. Partner auth uses X-PayFi-Api-Key, X-PayFi-Nonce, and X-PayFi-Signature. Mutating partner endpoints use Idempotency-Key. Tenant isolation derives organizationId and partnerIntegrationId from auth, never from the public body.

Decision Pack

operation_decision_packs is the operation-level audit contract. Representative fields (the published JSON Schema is authoritative for the complete required set):
The full persisted schema also includes operation facts, document coverage, entity reconciliation, nature decision, regulatory checks, policy checks, fraud signals, score breakdown, reason codes, source evidence, action items, redacted processing trace events, version metadata, and created timestamp. It does not persist prompt text, model raw output, document binaries, credentials, or PII-bearing traces.

Deterministic score

Score is calculated by deterministic rules over validated evidence. Each factor records its reason code, severity, source, and impact. If the required evidence is incomplete or a critical source is unavailable, the engine abstains and leaves score fields unset instead of fabricating a number. Status rules:
  • Any critical flag yields ACTION_REQUIRED.
  • Missing critical required document yields ACTION_REQUIRED.
  • Score >= 8 with no critical flag, complete sources, valid quality, and no fallback yields READY_FOR_MANUAL_REVIEW.
  • Score >= 6 and < 8 yields READY_FOR_MANUAL_REVIEW with REVIEW_WITH_WARNINGS.
  • Score < 6 yields ACTION_REQUIRED.
The score is operational guidance. It never approves an operation, and the model cannot freely generate the final score or status.

Reason codes

Core reason codes include: MISSING_REQUIRED_DOCUMENT, MISSING_CRITICAL_DOCUMENT, BANK_ACCOUNT_MISMATCH, BUYER_OWNER_MISMATCH, DOCUMENT_REFERENCE_MISMATCH, AMOUNT_MISMATCH, CURRENCY_MISMATCH, INVALID_TAX_ID, INVALID_SWIFT_BIC, INVALID_IBAN, NATURE_MISMATCH, LOW_OCR_CONFIDENCE, DUPLICATE_DOCUMENT_HASH, SUSPICIOUS_PDF_METADATA, NO_REGULATORY_SOURCE_FOUND, POLICY_RULE_TRIGGERED, POLICY_NOT_CONFIGURED, MALWARE_DETECTED, DOCUMENT_ANALYSIS_FAILED, UNTRUSTED_ANALYSIS_RESULT, SCHEMA_VALIDATION_FAILED, STALE_DECISION_PACK, MANUAL_REVIEW_REQUIRED, DOCUMENTS_VALIDATED, NATURE_CONFIRMED, HUMAN_OVERRIDE_APPLIED. Critical and high evidence problems are blocking by default. NO_REGULATORY_SOURCE_FOUND, POLICY_NOT_CONFIGURED, schema failure, degraded execution, or stale input blocks a ready result and requires remediation or review. A permitted human override remains a separate audit record; the original signal and impact stay in history.

Human review

Manual review accepts APPROVE, REJECT, REQUEST_CHANGES and the legacy lowercase equivalents. Payload:
The server persists reviewer ID, timestamp, latest Decision Pack ID when available, reason codes, comments, overrides, requested documents, previous status by audit trail, next status, and webhook delivery. Approval is accepted only against the latest current, complete, VALID Decision Pack with no critical blocker. A valid pack with a low score or contrary recommendation requires an override reason code and justification. REVIEW_REQUIRED, INVALID, and DEGRADED packs only allow rejection or requested changes. Human review does not mutate historical score. Overrides are audit records and may feed future datasets only after redaction/pseudonymization and legal approval.

Webhooks

Payloads are redacted and never include raw documents, OCR text, prompts, completions, presigned URLs, secrets, signatures, or full tax IDs. New fields are additive and backward-compatible:
Webhook deliveries are HMAC-signed, idempotent by context/event, retried with backoff, and logged with redacted payload and response body hash.

LGPD retention matrix

Regulatory obligations and active policy

Regulatory obligations follow:
Active internal policies follow:
No obligation or client policy can produce an autonomous ready result before human approval. Requirements resolve from an explicit policySet and natureCode. If the client policy is missing, PayFi applies the immutable versioned default policy, sets fallbackUsed=true, uses HUMAN_REVIEW_REQUIRED, and keeps the operation processable. The default is system-default-document-policy v1 with SHA-256 97ff1b55faa3209c1908cdb5b08c55f26f26236b58182fc481e01d6c32fe40c8. Invalid custom policy data falls back only in INTERNAL_SUPERVISED_ONLY; in authorized evaluation it is fail-closed as PARTNER_POLICY_NOT_CONFIGURED, with DOCUMENT_REQUIREMENT_POLICY_NOT_CONFIGURED retained as its legacy alias.

Scope controls

  • C212 is an auditable draft only; no STA submission.
  • Sanctions/PEP activates only with partner-provided source/list/policy and approval.
  • Legal fine-tuning remains out of MVP.
  • Future fine-tuning requires pseudonymized/anonymous data and legal approval.
  • Model selection is explicit and versioned. A model, OCR, policy, schema, workflow, or regulatory-source failure is fail-closed and cannot fall back to a ready result.
Decision needed:
  • owner: Product + Compliance PayFi
  • deadline: before Braza/B&T pilot with virtual asset operations
  • options: C212_DRAFT_ENABLED or C212_DRAFT_DISABLED
  • recommended default: C212_DRAFT_DISABLED
  • impact if unresolved: C212 can inflate MVP scope and delay the core analysis pilot

MVP Ready Checklist

  • Migrations applied in the API database.
  • Railway workflow Rsmrc2p5STzykAWj active and smoke-tested.
  • N8N_OPERATION_DECISION_URL points to /webhook/operation-decision-engine in the deployed API environment.
  • Operation happy path reaches READY_FOR_MANUAL_REVIEW with a persisted Decision Pack.
  • Missing critical document reaches ACTION_REQUIRED.
  • Manual approval/rejection only works via ManualReviewService.
  • Webhooks include redacted decisionPackId and decisionSummary.
  • Dashboard shows Decision Pack before manual review.
  • Schema-invalid n8n output does not persist operation analysis.
  • Policy/corpus versions appear in every Decision Pack.
  • Public logs and webhooks contain no raw document, OCR text, prompt, or PII.