For example, the correction
{
"schema_version": 2,
"corrections": [
{
"name": "hi",
"version": 2,
"output": { "name": "hi", "type": "real" },
"inputs": [{ "name": "blah", "type": "int" }],
"data": {
"nodetype": "category",
"input": "blah",
"content": [{ "key": "a", "value": "3.0" }]
}
}
]
}
has a content that should be a float but pydantic will happily validate and type-promote a string, e.g.
parsed = cs.CorrectionSet.model_validate_json(data)
print(parsed.corrections[0].data)
produces
nodetype='category' input='blah' content=[CategoryItem(key='a', value=3.0)] default=None
A similar issue is the source of the TODO in
|
# TODO: this is not detected by the pydantic model yet |
|
hard_json = '{"schema_version":2, "corrections": [{"name": "hi", "version": 2, "output": {"name": "hi","type": "real"}, "inputs": [{"name":"blah", "type": "int"}], "data": {"nodetype": "category", "input": "blah", "content": [{"key": "a", "value": 3.0}]}}]}' |
A solution could either:
- Do the same type promotion inside the C++ evaluator, or
- Configure pydantic to treat such cases as errors with strict mode
A potential workaround (or at least mechanism to catch such cases) in the correction validate CLI is to also construct an evaluator from the parsed model.
For example, the correction
{ "schema_version": 2, "corrections": [ { "name": "hi", "version": 2, "output": { "name": "hi", "type": "real" }, "inputs": [{ "name": "blah", "type": "int" }], "data": { "nodetype": "category", "input": "blah", "content": [{ "key": "a", "value": "3.0" }] } } ] }has a content that should be a float but pydantic will happily validate and type-promote a string, e.g.
produces
A similar issue is the source of the TODO in
correctionlib/tests/test_core_valid.py
Lines 47 to 48 in b6a3485
A solution could either:
A potential workaround (or at least mechanism to catch such cases) in the
correction validateCLI is to also construct an evaluator from the parsed model.