Type Annotation for Python Dictionary with multiple Value Types
09:19 07 Apr 2026

I have a custom class in python 3.14 that contains an object that is a list of dictionaries, where the dictionary keys are strings and the dictionary values can be a string or a list of strings.

class MyClass(OutputClass):
    object1: list[dict[str,str|list[str]]] | None

When serializing my code to export it, I'm given this error:

TypeError: Output field phones has invalid type annotation: dict[str, str | list[str]]

Is there another way to annotate the value of a dictionary that contains multiple types of values?

typing python-3.14