Python: Bug: Newly released Pydantic 2.9.0 breaks Semantic Kernel
Describe the bug Any use of Semantic Kernel with Pydantic 2.9.0 throws this error:
(... lots of other stuff ...)
File ~/.python/current/lib/python3.12/site-packages/pydantic/_internal/_discriminated_union.py:289, in _ApplyInferredDiscriminator._handle_choice(self, choice)
[278] self._choices_to_handle.extend(choices_schemas)
[279] elif choice['type'] not in {
[280] 'model',
[281] 'typed-dict',
(...)
[287] } and not _core_utils.is_function_with_inner_schema(choice):
[288] # We should eventually handle 'definition-ref' as well
--> [289] raise TypeError(
[290] f'{choice["type"]!r} is not a valid discriminated union variant;'
[291] ' should be a `BaseModel` or `dataclass`'
[292] )
[293] else:
[294] if choice['type'] == 'tagged-union' and self._is_discriminator_shared(choice):
[295] # In this case, this inner tagged-union is compatible with the outer tagged-union,
[296] # and its choices can be coalesced into the outer TaggedUnionSchema.
TypeError: 'list' is not a valid discriminated union variant; should be a `BaseModel` or `dataclass`
To Reproduce Steps to reproduce the behavior:
- Check out main branch
- Open in dev container
- Open a sample such as: python/samples/getting_started/00-getting-started.ipynb
- Run first cell
- See error
- Install Pydantic 2.8.2 (previous release), restart notebook kernel (if needed), re-run first cell, and notice it now works without error
Expected behavior No error.
Screenshots
Platform
- OS: Linux inside the SK dev container (in WSL)
- IDE: VS Code
- Language: Python
- Source: main branch of repository
Additional context None
Hello @brycecutt-msft, I am unable to repro this. The entire 00 getting_started notebook works well.
Granted, I am running locally on MacOS and not in a dev container -- but it should be the same if running from main.
On a personal machine, I am running the latest SK Python 1.8.2 pip package, and I am not seeing any error either.
With that said, the issue is known on the Pydantic side, and a patch should be rolled out today. We will get a new package out as soon as we pull in their fix. https://github.com/pydantic/pydantic/issues/10326
Update: we've released SK Python 1.8.3 which contains the fix for this error.