Skip to content

Normalize Lean 4.33 docstrings before pydantic validates them - #27

Merged
Gabrielebattimelli merged 1 commit into
mainfrom
fix/docstring-normalize
Aug 19, 2026
Merged

Normalize Lean 4.33 docstrings before pydantic validates them#27
Gabrielebattimelli merged 1 commit into
mainfrom
fix/docstring-normalize

Conversation

@Gabrielebattimelli

Copy link
Copy Markdown
Member

Why

Indexing is still blocked. jixia now builds fine against Lean 4.33 (the patch loop works), but the smoke test rejects its output — every declaration with a docstring fails:

0.modifiers.docString
  Input should be a valid tuple [type=tuple_type, input_value='The charge density. ', input_type=str]

Lean 4.32 emitted docString as a [text, bool] pair; 4.33 emits a bare string.

Why the previous fix didn't work

#26 widened Modifiers' annotation and called model_rebuild(force=True). That fixes Modifiers.model_validate(...) in isolation — which is presumably how it was checked — but not the real path.

Declaration and Symbol compile their own nested copy of Modifiers' schema when their classes are created. Rebuilding Modifiers afterwards leaves those copies validating against the original tuple-only type. Confirmed directly:

Modifiers.model_validate(...)          -> OK
Declaration.from_json_file(...)        -> docString tuple_type error

I also tried clearing __pydantic_core_schema__ / __pydantic_validator__ on the dependents and rebuilding — the error persisted (pydantic 2.13.4).

What

Normalize the raw JSON to the pair form before pydantic sees it. Every read goes through RootModel.from_obj, so this covers Declaration, Symbol, and anything else jixia loads, without depending on pydantic schema internals.

Verified

Using the shim exactly as written in the file:

4.33 string  -> ('doc', False)
4.32 tuple   -> ('doc', False)
none         -> None

Both Lean versions parse, so this doesn't break if a patch selects a 4.32-shaped build.

The previous fix widened Modifiers' docstring annotation and rebuilt the
model, but indexing still failed on every declaration carrying a docstring:

  0.modifiers.docString
    Input should be a valid tuple [input_value='The charge density. ']

Declaration and Symbol compile their own nested copy of Modifiers' schema when
their classes are created, so rebuilding Modifiers afterwards leaves those
copies validating against the original tuple-only type. The shim worked when
validating Modifiers directly, which is why it looked correct.

Normalize the raw JSON to the [text, bool] pair before pydantic sees it
instead. Every read goes through RootModel.from_obj, so this covers
Declaration, Symbol, and anything else jixia loads, and it does not depend on
pydantic's schema-rebuild internals. Verified against all three shapes: a 4.33
bare string, a 4.32 pair, and no docstring.
@Gabrielebattimelli
Gabrielebattimelli merged commit f0cbc7c into main Aug 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant