Skip to content

fix(config): report wrong-typed training values as validation errors - #2382

Merged
MakazhanAlpamys merged 4 commits into
MakazhanAlpamys:mainfrom
shu-chen-dot-ca:fix-2366-typeerror-validation
Nov 13, 2026
Merged

MakazhanAlpamys merged 4 commits into
MakazhanAlpamys:mainfrom
shu-chen-dot-ca:fix-2366-typeerror-validation

Conversation

@shu-chen-dot-ca

@shu-chen-dot-ca shu-chen-dot-ca commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Closes #2366, following the fix proposed in the issue, with the per-validator conversion from the review.

A wrong-typed value in 38 training fields (for example minillm_enabled: 0) raised a bare TypeError from a field validator. Pydantic does not convert a TypeError into a ValidationError, so soup train printed Error: TypeError: v0.70.0 MiniLLM flag must be bool, got int, soup plan exited 2, and load_config_from_string raised TypeError instead of its documented ValueError.

  • Per-validator conversion. A functools.wraps decorator, _type_error_as_value_error in config/schema.py, sits on the 24 TrainingConfig validators behind the 38 fields and re-raises a TypeError as a ValueError with the same text, so Pydantic reports it with the field's location. functools.wraps keeps the signature Pydantic inspects for info. The shared helpers (num_labels, distill_temperature, grace_codebook_* and so on) keep raising TypeError for their other callers.
    • An earlier head used one @field_validator("*", mode="wrap") instead. On the declared floor, Pydantic 2.0.0, that wrap strips the field context from every inner validator that takes info, so 27 fields raised RuntimeError there, valid values included (review above). It is removed.
  • Messages name the field. The five bool-guard validators that named a release (v0.70.0 MiniLLM flag must be bool, v0.53.0 flag must be bool, ...) now use info.field_name, e.g. minillm_enabled must be bool, got int.
  • Result. With training: {minillm_enabled: 0}, soup train and soup plan both print Config validation error: and training -> minillm_enabled: minillm_enabled must be bool, got int, and both exit 1.
  • Existing tests. Eight cases pinned the old TypeError: test_v0530.py::TestLFParity::test_bool_guards_reject_int (7 fields) and test_v0610_part_a.py::TestSchemaUnlearnTask::test_unlearn_alpha_bool_rejected. They now expect a validation error that names the field. The test_v0530.py case validates through SoupConfig directly, because for quantize_ref_model the loader now reaches its "read by nothing; refused as of v0.77" refusal before the bool guard, which the TypeError used to hide.
  • Floor coverage. tests/test_config_field_types.py is added to the core-floor job's pytest list in .github/workflows/ci.yml and to REQUIRED_TESTS in tests/test_core_dependency_floors.py, so it runs on Pydantic 2.0.0.

Changelog: changelog.d/0.77.2/2382.fixed.md.

Type of change

  • Bug fix
  • New feature
  • Refactor / cleanup
  • Documentation
  • Tests

What I ran

  • New tests/test_config_field_types.py walks every field of every model reachable from SoupConfig with 0, true, "false", [], {} and 1.5 and accepts only success or ValidationError; it also checks every field accepts its own default, six bool flags accept True/False, load_config_from_string raises ValueError naming training -> <field>, and soup train / soup plan exit 1 with Config validation error:.
  • Pydantic 2.0.0 with the core-floor constraints (Python 3.11): the file gives 688 passed, 6 skipped; the core-floor job's pytest command with it added gives 875 passed, 8 skipped. The previous head c9018fad fails 72 cases of the file there.
  • Pydantic 2.14.2: the same file passes; with the decorators removed, 47 cases fail on both 2.0.0 and 2.14.2.
  • ruff check src/soup_cli/ scripts/ tests/ benchmarks/ passes.
  • Full suite on Python 3.12 / Pydantic 2.14.2, pytest tests/ -n 8 --dist loadfile with the default coverage addopts: 49005 passed, 561 skipped.
Before After
Error: TypeError: v0.70.0 MiniLLM flag must be bool, got int (exit 1); soup plan exits 2 Config validation error: / training -> minillm_enabled: minillm_enabled must be bool, got int (exit 1 for both)

AI assistance: Claude (Anthropic) implementation and verification.

Checklist

  • ruff check src/soup_cli/ scripts/ tests/ passes
  • pytest tests/ -v passes (run with -n 8 --dist loadfile -q instead of -v; full suite)
  • Updated relevant docs (README.md and the matching page under docs/) if needed (no field, type, default or bound changed, so the generated reference pages are untouched)
  • Added a changelog fragment, or this change has no user-visible impact
  • My contribution is licensed under Apache-2.0, the project's own terms (see CONTRIBUTING.md)

@shu-chen-dot-ca

Copy link
Copy Markdown
Contributor Author

Renamed the changelog fragment to changelog.d/0.77.1/2382.fixed.md and made it reference #2382 (closes #2366), as the fragment README asks. No code change; tests/test_issue487_changelog_fragments.py (21 passed) and repository Ruff pass.

@Nari-Ab Nari-Ab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. I found a compatibility regression on the declared minimum Pydantic 2.0.0, verified against this PR's current head c9018fad42373d7404fe23e857b330286c578e8d (macOS, Python 3.11).

With Pydantic 2.0.0, both of these valid inputs now raise RuntimeError, rather than building a config:

from soup_cli.config.schema import TrainingConfig

TrainingConfig(minillm_enabled=False)
TrainingConfig(fp8_attention=False)

The error is:

This validator expected to be run inside the context of a model field but no model field was found

TrainingConfig(minillm_enabled=0) raises the same RuntimeError, so the original refusal contract also remains broken on the floor. These cases produce the expected results on Pydantic 2.13.5. The outer wildcard wrap handler loses the field context of the inner info-consuming before validators on 2.0.

Please cover both the valid boolean case and the invalid-type case on the declared floor before merging. A working alternative is a shared TypeError-to-ValueError decorator on the schema callbacks themselves, preserving their signatures with functools.wraps. That leaves the runtime helpers unchanged and avoids the outer wrap issue.

I prepared that alternative in Nari-Ab/Soup, codex/config-type-errors-2366, commit ce132070. It is based on main at c38330cf and is available for comparison or adaptation. My implementation and tests were written independently before I noticed this PR. I have not opened a competing PR. If you incorporate code from the linked branch, please retain my attribution for those changes.

Validation of that alternative: 31 new cases pass on both Pydantic 2.0.0 and 2.13.5; the related suite passes 1,374 tests with one skip. The field walk covers 336 fields across eight models with six values each. Removing the converter makes all six field-walk cases fail. No full local suite or native Windows/Linux run is claimed.

AI assistance: OpenAI Codex implementation and verification.

@shu-chen-dot-ca

Copy link
Copy Markdown
Contributor Author

Thanks @Nari-Ab, confirmed on Pydantic 2.0: the outer "*" wrap validator strips the field context from every inner validator that takes info, so 27 fields raised RuntimeError there, valid values included (also the two pre-existing grpo_judge_* / GRPO numeric validators). I did not use your branch; this is a separate implementation along the lines you suggested.

  • Removed the wrap validator. A functools.wraps decorator, _type_error_as_value_error, now sits on the 24 TrainingConfig validators behind the 38 fields, so the shared helpers still raise TypeError for their other callers.
  • Tests: every field still accepts its own default, and the bool flags accept True/False. tests/test_config_field_types.py now runs in the core-floor job and is listed in REQUIRED_TESTS.
  • Pydantic 2.0.0 (core-floor constraints, Python 3.11) and 2.14.2: 694 passed, 6 skipped in test_config_field_types.py + test_core_dependency_floors.py. With the previous head on 2.0, 72 of these fail; with the decorators removed, 47 fail on both versions.
  • Full suite on Python 3.12 / Pydantic 2.14.2 (pytest tests/ -n 8 --dist loadfile): 49005 passed, 561 skipped; Ruff clean.

@MakazhanAlpamys

Copy link
Copy Markdown
Owner

Thank you, @shu-chen-dot-ca, for the rework, and for answering the review of @Nari-Ab so quickly and plainly. This is the first word from the maintainers on this pull request, so here is the whole standing.

Nothing else is asked of you now. We will say here when the decision on the workflow line and the validators is made.

@shu-chen-dot-ca

Copy link
Copy Markdown
Contributor Author

Thanks @MakazhanAlpamys. Yes: on head 92ddeeff0, tests/test_config_field_types.py runs both cases on Pydantic 2.0.0.

  • Valid booleans: test_bool_flags_accept_bools builds TrainingConfig with True and False for six bool flags (including minillm_enabled and fp8_attention from the review) and checks the value round-trips; test_default_value_still_validates also validates every field of every reachable model with its own default.
  • Invalid types: test_wrong_typed_value_is_a_validation_error feeds 0, true, "false", [], {} and 1.5 to every field and accepts only success or ValidationError (a RuntimeError or TypeError fails it); the loader and CLI cases check training -> <field> and exit 1.

Run with the core-floor constraints (Python 3.11; pydantic 2.0, typer 0.15.4, click 8.0.0, rich 13.0.0, pyyaml 6.0): the file alone gives 688 passed, 6 skipped, and the job's full pytest command with this file added gives 875 passed, 8 skipped. On the previous head c9018fad the same file fails 72 cases on 2.0.0.

I'll update the description to match the current head.

@MakazhanAlpamys MakazhanAlpamys left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shu-chen-dot-ca, an update on the decision that was still open on this pull request.

The maintainer has decided the error form for wrong-typed config values: the error is reported against the field (training -> minillm_enabled), each field keeps its own existing message where one exists, and a model-level conversion whose error sits at training is not taken.

This pull request already has that form, so nothing in it needs to change for the decision. By reading the diff at 92ddeeff:

  • _type_error_as_value_error (src/soup_cli/config/schema.py:47) converts inside each of the 24 validators and re-raises with str(exc), so Pydantic puts the error on training -> <field> and the text stays the validator's own, including the helper texts such as num_labels must not be bool.
  • tests/test_config_field_types.py pins that location for the loader (:109) and for soup train and soup plan (:128).
  • The five bool guards that named a release now name the field, which is what #2366 asked for in its proposed fix.

Still open, and separate from the code: the line that adds tests/test_config_field_types.py to the core-floor job (.github/workflows/ci.yml:696, with the REQUIRED_TESTS entry at tests/test_core_dependency_floors.py:36) is a maintainer decision that has not been made yet, and the checks start after it. Nothing is needed from you in the meantime. Thank you as well for bringing the description in line with the current head.

On #2366 this pull request goes first; #2419 and #2462 rebase after it.

@MakazhanAlpamys MakazhanAlpamys added the ci:full Run the full CI matrix on this PR (a maintainer adds it at approval) label Nov 4, 2026
@MakazhanAlpamys

Copy link
Copy Markdown
Owner

@shu-chen-dot-ca, an update: the line that adds tests/test_config_field_types.py to the core-floor job (.github/workflows/ci.yml:696, with the REQUIRED_TESTS entry at tests/test_core_dependency_floors.py:36) is accepted, as one line in an existing list with its guard entry. The rename of the five bool-guard messages to {field} must be bool, got <type>, which #2366 asked for, stays as it is. The checks are being started on 92ddeeff now; nothing is needed from you.

@MakazhanAlpamys

Copy link
Copy Markdown
Owner

@shu-chen-dot-ca, thank you for the rework to per-validator decorators and for the floor evidence. A correction to our comment of 4 Nov (#2382 (comment)), which said the checks were being started on 92ddeeff. Only part of them ran.

What has run on 92ddeeff is the quick set: lint, gate, validate-recipes and test (ubuntu-latest, 3.12) are green. The cells this pull request is about have no result yet:

  1. core-floor, the job that now lists tests/test_config_field_types.py and runs on Pydantic 2.0.0, was skipped.
  2. test (ubuntu-latest, 3.11), test (macos-latest, 3.12) and test (windows-latest, 3.12) did not run.
  3. The full run that the ci:full label started on 4 Nov (https://github.com/MakazhanAlpamys/Soup/actions/runs/41807939851) waited at "action required" until today: the runs of a first contribution wait for a maintainer to start them, and this branch also edits .github/workflows/ci.yml (the one line in the core-floor file list). It has now been started, and its result will show here.

So the Pydantic 2.0.0 numbers in the description (688 passed, 6 skipped for the file) come from your own run, and CI confirms them when that run ends. Nothing is needed from you for this.

@MakazhanAlpamys MakazhanAlpamys left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shu-chen-dot-ca, the checks that were waiting have now run on 92ddeeff, and they confirm the part of this change that mattered most. core-floor installed Pydantic 2.0, ran tests/test_config_field_types.py from the line you added to its list, and ended with 875 passed, 8 skipped, the same count as in your description. lint, mlx-smoke, transformers-floor, pytorch-smoke and test on ubuntu 3.11, ubuntu 3.12, macOS 3.12 and Windows 3.12 are green too. By reading the diff, the decorator does what the description says: functools.wraps keeps info working on the floor, and the field walk (tests/test_config_field_types.py:53-60) fails for any validator that lets a TypeError out, so a new field cannot bring the bug back. Thank you for the careful rework.

One thing is left before this can merge, and it is about timing rather than your code.

  1. Move the changelog fragment to changelog.d/0.77.2/. Those checks ran on a merge with main as it was on 3 Nov, when the latest release was v0.77.1. v0.77.2 was released on 5 Nov, and changelog.d/ on main now holds only 0.77.2/. By reading, changelog.d/0.77.1/2382.fixed.md is therefore rejected by tests/test_issue487_changelog_fragments.py::test_repository_fragments_match_the_newest_release (line 256) with "fragment baseline is 0.77.1, but the latest release is 0.77.2" (scripts/assemble_changelog.py:96-101). We have not run it, and the green checks above cannot show it. Please move it yourself, because maintainers do not push to contributors' branches. A trial merge of the branch with today's main shows no conflicts, so a rebase is not needed; the move and a push are enough:
git mv changelog.d/0.77.1/2382.fixed.md changelog.d/0.77.2/2382.fixed.md
git commit -m "docs(changelog): move the #2382 fragment to 0.77.2"
git push
  1. While the file is open, end the entry with your credit, the way entries for outside work end: replace (#2382, closes #2366) with (#2382 by @shu-chen-dot-ca, closes #2366). The Changelog: line in the description names the old path; please update it as well.

The push starts a new run. For a first contribution it waits for a maintainer to start it, as the first one did, so "action required" is expected for a while; nothing more is needed from you for that.

@shu-chen-dot-ca

Copy link
Copy Markdown
Contributor Author

Moved the fragment to changelog.d/0.77.2/2382.fixed.md and ended it with (#2382 by @shu-chen-dot-ca, closes #2366), as one commit on top of 92ddeeff. On a local merge of this branch with today's main (no conflicts), ruff check src/soup_cli/ scripts/ tests/ benchmarks/ and the full pytest tests/ -n 4 --dist loadfile pass (52417 passed, 585 skipped), including test_repository_fragments_match_the_newest_release.

@MakazhanAlpamys

Copy link
Copy Markdown
Owner

Thank you, @shu-chen-dot-ca, for d90a985. Both items of our review of 2026-11-08 are done:

  1. The fragment is now changelog.d/0.77.2/2382.fixed.md. The commit renames that one file and touches nothing else (compare 92ddeeff...d90a985: 1 file, +1/-1).
  2. The entry ends (#2382 by @shu-chen-dot-ca, closes #2366), and the Changelog: line of the description names the new path.

The hosted checks on this head ran after your push and are all green: lint, gate, validate-recipes, core-floor (Pydantic 2.0.0, with tests/test_config_field_types.py in its list), transformers-floor, mlx-smoke, pytorch-smoke, and test on ubuntu 3.11, ubuntu 3.12, macOS 3.12 and Windows 3.12. merge-freshness is neutral as of 2026-11-13 06:41Z, so the branch does not conflict with main.

Nothing else is asked of you. Reading verdict: READY-BY-READING. The change turns a bare TypeError into a named validation error on training -> <field>, which is the error form the maintainer decided on 2026-11-04, and the one line in .github/workflows/ci.yml was accepted in our comment of the same day.

By reading; nothing was run here.

The hosted runs, labels and merge order are answered separately in this thread.

@MakazhanAlpamys
MakazhanAlpamys merged commit 4d7afd1 into MakazhanAlpamys:main Nov 13, 2026
18 checks passed
@MakazhanAlpamys

Copy link
Copy Markdown
Owner

Thank you, @shu-chen-dot-ca, for #2382. It is the pull request that went first on #2366: a wrong-typed training value is now a validation error on training -> <field> from soup train, soup plan and load_config_from_string, and the five bool guards that named a release now name the field. When the review of @Nari-Ab showed that the wildcard wrap validator of the issue loses the field context on Pydantic 2.0.0, you confirmed it the same day, replaced it with a decorator on the individual validators, and put the floor numbers in the description (688 passed and 6 skipped for the new file, 72 of its cases failing on the previous head) and the file itself in the core-floor job, where it now runs on every full run. The field walk is the guard: a validator added later that lets a TypeError out fails it. The one workflow line was accepted on 2026-11-04, and both items of our review of 2026-11-08 are done in d90a985, a commit that renames the fragment to changelog.d/0.77.2/ and touches nothing else. On the head, the 688 cases pass in the Ubuntu 3.11, Ubuntu 3.12, macOS 3.12 and Windows 3.12 jobs and the Pydantic 2.0 core-floor job of our CI.

MakazhanAlpamys added a commit that referenced this pull request Nov 13, 2026
Display names from `gh api users/<login>`.
@shu-chen-dot-ca
shu-chen-dot-ca deleted the fix-2366-typeerror-validation branch November 13, 2026 07:38
wanjinhao1 pushed a commit to wanjinhao1/Soup that referenced this pull request Nov 23, 2026
…akazhanAlpamys#2382)

A wrong-typed value in one of 38 `training` fields (for example `minillm_enabled: 0`, `fp8_attention: "false"` or `num_labels: true`) raised a bare `TypeError` from a field validator. Pydantic does not turn a `TypeError` into a `ValidationError`, so `soup train` printed `Error: TypeError: v0.70.0 MiniLLM flag must be bool, got int`, `soup plan` exited 2, and `load_config_from_string` raised `TypeError` where it documents `ValueError` (MakazhanAlpamys#2366). The value is now a config validation error on `training -> <field>`, with exit 1 from both `soup train` and `soup plan`.

`_type_error_as_value_error` in `src/soup_cli/config/schema.py` is a `functools.wraps` decorator on the 24 `TrainingConfig` validators behind those 38 fields. It re-raises a `TypeError` as a `ValueError` with the same text, so Pydantic reports it with the field's location, and `functools.wraps` keeps the signature Pydantic inspects to decide whether a validator takes `info`. The shared helpers (`num_labels`, `distill_temperature`, the `grace_codebook_*` checks and others) keep raising `TypeError` for their other callers. The first head used one `@field_validator("*", mode="wrap")`, as the issue proposed; on the declared floor, Pydantic 2.0.0, that wrap strips the field context from every validator that takes `info`, and a review by @Nari-Ab found `TrainingConfig(minillm_enabled=False)` raising `RuntimeError` there, so it was replaced. The five bool-guard validators that named a release (`v0.70.0 MiniLLM flag must be bool`, `v0.53.0 flag must be bool` and the others) now name the field, for example `minillm_enabled must be bool, got int`.

`tests/test_config_field_types.py` walks every field of every model reachable from `SoupConfig` with `0`, `true`, `"false"`, `[]`, `{}` and `1.5` and accepts only success or `ValidationError`; it also checks that every field accepts its own default, that six bool flags accept `True` and `False`, that `load_config_from_string` raises `ValueError` naming `training -> <field>`, and that `soup train` and `soup plan` exit 1 with `Config validation error:`. Eight existing cases that pinned the old `TypeError` (`test_bool_guards_reject_int` in `tests/test_v0530.py` for 7 fields and `test_unlearn_alpha_bool_rejected` in `tests/test_v0610_part_a.py`) now expect a validation error that names the field. The file is added to the pytest list of the `core-floor` job in `.github/workflows/ci.yml` (the one change to a workflow: one appended line) and to `REQUIRED_TESTS` in `tests/test_core_dependency_floors.py`, so it runs on Pydantic 2.0.0. The change carries the fragment `changelog.d/0.77.2/2382.fixed.md`.

What users notice: a wrong-typed `training` value ends in `Config validation error:` with a line naming `training -> <field>` and exit 1, instead of a `TypeError` line, and `soup plan` exits 1 where it exited 2 for these configs. A value that loaded on v0.77.2 still loads; only values that already crashed change.

Verified by CI on the head `d90a9856` (labelled `ci:full`), merged with `2db8e0c55` by GitHub's test merge: lint, mlx-smoke, transformers-floor and pytorch-smoke succeeded, `core-floor` succeeded on Pydantic 2.0 (job 131004079243, 875 passed, 8 skipped), and so did the test cells ubuntu 3.11 (job 131004079203, 55261 passed, 598 skipped), ubuntu 3.12 (job 131004079360, 55266 passed, 593 skipped), macOS 3.12 (job 131004079212, 55245 passed, 614 skipped) and Windows 3.12 (job 131004079239, 55131 passed, 728 skipped). In all four test job logs `tests/test_config_field_types.py` ran 688 cases that passed and 6 skipped, and none failed. No test was run locally for this pull request.

Closes MakazhanAlpamys#2366
wanjinhao1 pushed a commit to wanjinhao1/Soup that referenced this pull request Nov 23, 2026
Display names from `gh api users/<login>`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:full Run the full CI matrix on this PR (a maintainer adds it at approval)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A wrong-typed value in 38 training fields escapes the schema as a TypeError: soup train prints Error: TypeError: ... and soup plan exits 2

3 participants