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):
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
>= 8with no critical flag, complete sources, valid quality, and no fallback yieldsREADY_FOR_MANUAL_REVIEW. - Score
>= 6and< 8yieldsREADY_FOR_MANUAL_REVIEWwithREVIEW_WITH_WARNINGS. - Score
< 6yieldsACTION_REQUIRED.
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 acceptsAPPROVE, REJECT, REQUEST_CHANGES and the legacy lowercase equivalents.
Payload:
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:LGPD retention matrix
Regulatory obligations and active policy
Regulatory obligations follow: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.
- owner: Product + Compliance PayFi
- deadline: before Braza/B&T pilot with virtual asset operations
- options:
C212_DRAFT_ENABLEDorC212_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
Rsmrc2p5STzykAWjactive and smoke-tested. -
N8N_OPERATION_DECISION_URLpoints to/webhook/operation-decision-enginein the deployed API environment. - Operation happy path reaches
READY_FOR_MANUAL_REVIEWwith a persisted Decision Pack. - Missing critical document reaches
ACTION_REQUIRED. - Manual approval/rejection only works via
ManualReviewService. - Webhooks include redacted
decisionPackIdanddecisionSummary. - 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.