Sanitise text to ISO 20022 charset
sanitize_to_iso20022_charsetTransliterate accented characters and replace unsupported symbols in one text field to meet the ISO 20022 SWIFT character set, returning original, sanitized value, and change flags.
Instructions
Sanitise one free-text field to a SWIFT / ISO 20022 character set.
Use this on a single free-text value (name, remittance info) to
transliterate accents and drop unsupported symbols before placing it in
a record, and to see whether the value changed. Operates on one string;
to check a whole batch's rulebook compliance use ``validate_payment_scheme``.
Two character sets are supported via ``charset``:
* ``"SWIFT_X"`` (default, backward-compatible) - the basic set used in
most ISO 20022 / pain.001 fields. Delegates to
:func:`pain001.sanitize_to_charset`.
* ``"SWIFT_Z"`` - the SWIFT extended set, a strict superset of X that also
permits ``= ! " % & * < > ; { @ # _`` (used in narrative / envelope
fields). It does not permit ``|`` or ``}``.
In both cases accents are transliterated (``é`` -> ``e``) and any remaining
out-of-set character is replaced with a space. The result includes flags
for whether the original was already valid and whether it changed - useful
for surfacing the change to the user before writing it back to a record.
Args:
value: The text to sanitise.
charset: ``"SWIFT_X"`` (default) or ``"SWIFT_Z"``.
Returns:
``{"value": str, "sanitised": str, "was_valid": bool, "changed": bool}``.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| value | Yes | A single free-text field value (e.g. a name or remittance line) to transliterate to the ISO 20022 Latin character set. | |
| charset | No | Which SWIFT character set to sanitise against. 'SWIFT_X' (default) is the basic set permitted in most ISO 20022 / pain.001 fields: letters, digits, space and the punctuation / - ? : ( ) . , ' + . 'SWIFT_Z' is the extended superset that additionally allows = ! " % & * < > ; { @ # _ (used in narrative / envelope fields); it does NOT allow | or }. Pick SWIFT_Z only when the target field is documented as Z-set. | SWIFT_X |