The immediate destination is the ACH file-header field that identifies the receiving financial institution by routing number. During file processing, it should match one of the bank’s known routing numbers. A mismatch can indicate that a file belongs to another institution, creating privacy, disclosure, and regulatory risks—especially in multitenant systems. Because mergers and acquisitions can change a bank’s routing numbers, validation should use a maintained list rather than a permanently hardcoded value. section 8.3.1
A practical validation workflow includes:
- Maintain a database table containing routing numbers recognized as belonging to the bank. section 8.3.1 section 8.5.3
- Validate the immediate destination against that runtime list with a Pydantic field_validator. section 8.5.3
- Raise a specific error when the value is not an allowed routing number, and a separate error when validation cannot be completed. section 8.5.3
- Account for performance, although one ACH file normally has only one file-header record to validate. section 8.5.3
Listing 8.17 Pydantic field validator for immediate destination
@field_validator('immediate_destination') #1 @classmethod #2 def validate_immediate_destination(cls, v): try: if BankRoutingSql().valid_bank_routing_number(v): #2 return v #3 else: #3 raise ValueError('immediate_destination #3 ➥ is not a valid routing number') #3 except Exception: #4 raise ValueError('Unable to validate #4 ➥ immediate_destination') #4
The validator listing shows the implementation pattern: inspect the field, query the bank-routing service, return valid values, and convert failures into validation errors. section 8.5.3
