阅读文本 / Reading text
This paper uses synthetic samples to demonstrate the processing method. The code has been verified using examples in an isolated environment; this does not guarantee effectiveness for all real files or products. Before processing important files, please retain the original copies and verify them against the boundaries and acceptance criteria outlined in this document.
writes all amount fields as
minimum: 0
, though seemingly rigorous on the surface, ends up blocking legitimate refund records. Whether the amount has been converted into a numeric value and whether this transaction permits negative numbers are two separate issues. One should first confirm the meaning of the document before defining the scope rules.
first defines what the minus sign represents
This paper’s synthesis protocol stipulates: standard charges are non-negative, and refunds are represented by negative amounts. Real-world systems may also employ an accounting approach of “positive amounts plus refund types.” Both approaches are valid, but they must not be left to the reader’s interpretation within the same interface. The zero-boundary here is a sample protocol, not a unified industry standard.
lets the type determine the constraint
JSON Schema's
minimum
includes the boundary,
exclusiveMinimum
Does not include boundaries. If the business requirement is strictly positive, it cannot be used
minimum: 0
. First list scenarios that permit zero values, then select keywords to avoid misclassifying free items, write-offs, or estimated values as errors.
from jsonschema import Draft202012Validator
schema = {
"type": "object", "required": ["kind", "amount"],
"additionalProperties": False,
"properties": {"kind": {"enum": ["charge", "refund"]},
"amount": {"type": "number"}},
"allOf": [
{"if": {"properties": {"kind": {"const": "charge"}}},
"then": {"properties": {"amount": {"minimum": 0}}}},
{"if": {"properties": {"kind": {"const": "refund"}}},
"then": {"properties": {"amount": {"exclusiveMaximum": 0}}}}
]
}
v = Draft202012Validator(schema)
valid = lambda x: not list(v.iter_errors(x))
assert valid({"kind": "charge", "amount": 0})
assert valid({"kind": "refund", "amount": -12.5})
assert not valid({"kind": "refund", "amount": 12.5})
assert not valid({"kind": "charge", "amount": True})
assert not valid({"amount": 12.5})
example depends on
jsonschema
, validated according to Draft 2020-12. It neither performs currency conversion nor verifies the relationship between subtotals and totals. Currency calculations require explicit precision and rounding strategies; one should not arbitrarily accumulate values using floating-point arithmetic simply because the data conforms to the schema.
error reporting must specify the business context
observation
The processing here
still needs to be verified against
refund is a positive number
rejects
is a symbol loss or does the source adopt another protocol
charges zero
accepts the structure
Whether it is a free project
amount is a string
rejection type
Thousand separator, currency, and decimal rules
type missing
rejects
does not infer the document type based on the amount symbol
Do not use automatic absolute value to mask errors
OCR misses hyphens, translates the negative sign as a shift, and the business adopts an opposite sign convention, which may manifest as the same anomaly. Directly invoking
abs()
will eliminate the most critical diagnostic clues. The original text segment, page number, and pre-parsing string should be preserved before deciding whether to re-extract or perform manual review.
checks the amount and type together upon delivery
uses
OmniDoc (Product Entry)
When processing documents containing monetary amounts, this rule table can be used as part of post-editing validation: it’s not enough to simply check whether any numbers have been omitted; one must also verify that contexts such as refunds and credit memos remain unchanged. Although tools can assist with translation, the agreed-upon monetary terms should still be explicitly confirmed by the business side.
Reference:
JSON Schema numeric constraints
。
- 1 -
Updated 2026-10-08