ML Foundations
Require ASCII digits in an identifier
Python's str.isdecimal accepts Unicode decimal characters; combine it with isascii when an identifier requires ASCII digits.

Evidence and testing
Review record: Tensor Almanac automated evidence gate (no independent human review). Example versions, recorded outputs and limitations appear below.
Decimal does not mean ASCII
Python's str.isdecimal() checks whether a non-empty string consists of Unicode decimal characters. That includes characters such as full-width digits, so a value can pass isdecimal() while containing no ASCII digit. Python documents isascii() separately as the check for characters in the ASCII range. [1]
This distinction matters when an external identifier's format explicitly uses ASCII digits. A test like value.isdecimal() answers whether the characters are Unicode decimal characters. It does not enforce the narrower character set some file formats, legacy interfaces, or protocol fields require. [1]
References: [1]
Combine the checks with the format rule
The example defines a four-character numeric code as len(value) == 4, value.isascii(), and value.isdecimal(). It compares ordinary digits with full-width digits, a superscript digit, and a string containing a hyphen. The output shows why each condition expresses a different part of the format. [1, 2]
isdecimal() rejects the superscript two because it is a digit but not a decimal character. Full-width digits are decimal characters, but isascii() rejects them. The ASCII check alone is broad, so the length and decimal checks still matter. [1, 2]
Executed with Python 3.12.14; assertions passed and exact stdout is recorded in private evidence.
def is_ascii_code(value):
return len(value) == 4 and value.isascii() and value.isdecimal()
values = ["2048", "2048", "²", "20-8"]
for value in values:
print(f"{value!r}: decimal={value.isdecimal()}, ascii={value.isascii()}, code={is_ascii_code(value)}")
assert is_ascii_code("2048")
assert "2048".isdecimal() and not "2048".isascii()
assert not "²".isdecimal()
assert not is_ascii_code("20-8")
Recorded output
'2048': decimal=True, ascii=True, code=True '2048': decimal=True, ascii=False, code=False '²': decimal=False, ascii=False, code=False '20-8': decimal=False, ascii=True, code=False
Keep validation specific to the identifier
Use the predicate that matches the input contract. If Unicode decimal digits are valid, isascii() would reject legitimate values. If the identifier has a prefix, separators, or a checksum, encode and test those rules too. The example demonstrates character-set and length checks, not a complete account or security validator.
The checks are ordinary string methods, so they need no dependency or conversion step. Keep the original text when leading zeros are meaningful; converting it to an integer would discard that formatting information.
References: [1]