<h3 dir="auto">First Check</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I added a very descriptive title to this issue.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I used the GitHub search to find a similar issue and didn't find it.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I searched the FastAPI documentation, with the integrated search.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already searched in Google "How to X in FastAPI" and didn't find any information.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already read and followed all the tutorial in the docs and didn't find an answer.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already checked if it is not related to FastAPI but to <a href="https://github.com/samuelcolvin/pydantic">Pydantic</a>.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already checked if it is not related to FastAPI but to <a href="https://github.com/swagger-api/swagger-ui">Swagger UI</a>.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already checked if it is not related to FastAPI but to <a href="https://github.com/Redocly/redoc">ReDoc</a>.</li>
</ul>
<h3 dir="auto">Commit to Help</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I commit to help with one of those options <g-emoji class="g-emoji" alias="point_up_2" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f446.png">👆</g-emoji></li>
</ul>
<h3 dir="auto">Example Code</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import typing

import fastapi
import httpx
import pydantic as pydantic
import pytest
from fastapi import FastAPI
from fastapi.encoders import jsonable_encoder
from pydantic import ValidationError
from starlette import status
from starlette.responses import JSONResponse


class ResponseOne(pydantic.BaseModel):
    val: str


class ResponseTwo(pydantic.BaseModel):
    val: str


app = FastAPI()
incorrect_response = {&quot;abc&quot;: &quot;def&quot;}


@app.exception_handler(ValidationError)
async def validation_exception_handler(request: fastapi.Request, exc: ValidationError):
    return JSONResponse(
        status_code=status.HTTP_400_BAD_REQUEST,
        content=jsonable_encoder({&quot;detail&quot;: exc.errors()}),
    )


@app.get(&quot;/union&quot;, response_model=typing.Union[ResponseOne, ResponseTwo])
async def union():
    return incorrect_response


@app.get(&quot;/single&quot;, response_model=ResponseOne)
async def single():
    return incorrect_response


@pytest.fixture
async def client():
    async with httpx.AsyncClient(app=app, base_url=&quot;http://localhost&quot;) as client:
        yield client


async def test_unprintable(client):
    res = await client.get(&quot;/union&quot;)
    assert res.status_code == 400


async def test_400(client):
    res = await client.get(&quot;/single&quot;)
    assert res.status_code == 400"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">typing</span>

<span class="pl-k">import</span> <span class="pl-s1">fastapi</span>
<span class="pl-k">import</span> <span class="pl-s1">httpx</span>
<span class="pl-k">import</span> <span class="pl-s1">pydantic</span> <span class="pl-k">as</span> <span class="pl-s1">pydantic</span>
<span class="pl-k">import</span> <span class="pl-s1">pytest</span>
<span class="pl-k">from</span> <span class="pl-s1">fastapi</span> <span class="pl-k">import</span> <span class="pl-v">FastAPI</span>
<span class="pl-k">from</span> <span class="pl-s1">fastapi</span>.<span class="pl-s1">encoders</span> <span class="pl-k">import</span> <span class="pl-s1">jsonable_encoder</span>
<span class="pl-k">from</span> <span class="pl-s1">pydantic</span> <span class="pl-k">import</span> <span class="pl-v">ValidationError</span>
<span class="pl-k">from</span> <span class="pl-s1">starlette</span> <span class="pl-k">import</span> <span class="pl-s1">status</span>
<span class="pl-k">from</span> <span class="pl-s1">starlette</span>.<span class="pl-s1">responses</span> <span class="pl-k">import</span> <span class="pl-v">JSONResponse</span>


<span class="pl-k">class</span> <span class="pl-v">ResponseOne</span>(<span class="pl-s1">pydantic</span>.<span class="pl-v">BaseModel</span>):
    <span class="pl-s1">val</span>: <span class="pl-s1">str</span>


<span class="pl-k">class</span> <span class="pl-v">ResponseTwo</span>(<span class="pl-s1">pydantic</span>.<span class="pl-v">BaseModel</span>):
    <span class="pl-s1">val</span>: <span class="pl-s1">str</span>


<span class="pl-s1">app</span> <span class="pl-c1">=</span> <span class="pl-v">FastAPI</span>()
<span class="pl-s1">incorrect_response</span> <span class="pl-c1">=</span> {<span class="pl-s">"abc"</span>: <span class="pl-s">"def"</span>}


<span class="pl-en">@<span class="pl-s1">app</span>.<span class="pl-en">exception_handler</span>(<span class="pl-v">ValidationError</span>)</span>
<span class="pl-k">async</span> <span class="pl-k">def</span> <span class="pl-en">validation_exception_handler</span>(<span class="pl-s1">request</span>: <span class="pl-s1">fastapi</span>.<span class="pl-v">Request</span>, <span class="pl-s1">exc</span>: <span class="pl-v">ValidationError</span>):
    <span class="pl-k">return</span> <span class="pl-v">JSONResponse</span>(
        <span class="pl-s1">status_code</span><span class="pl-c1">=</span><span class="pl-s1">status</span>.<span class="pl-v">HTTP_400_BAD_REQUEST</span>,
        <span class="pl-s1">content</span><span class="pl-c1">=</span><span class="pl-en">jsonable_encoder</span>({<span class="pl-s">"detail"</span>: <span class="pl-s1">exc</span>.<span class="pl-en">errors</span>()}),
    )


<span class="pl-en">@<span class="pl-s1">app</span>.<span class="pl-en">get</span>(<span class="pl-s">"/union"</span>, <span class="pl-s1">response_model</span><span class="pl-c1">=</span><span class="pl-s1">typing</span>.<span class="pl-v">Union</span>[<span class="pl-v">ResponseOne</span>, <span class="pl-v">ResponseTwo</span>])</span>
<span class="pl-k">async</span> <span class="pl-k">def</span> <span class="pl-en">union</span>():
    <span class="pl-k">return</span> <span class="pl-s1">incorrect_response</span>


<span class="pl-en">@<span class="pl-s1">app</span>.<span class="pl-en">get</span>(<span class="pl-s">"/single"</span>, <span class="pl-s1">response_model</span><span class="pl-c1">=</span><span class="pl-v">ResponseOne</span>)</span>
<span class="pl-k">async</span> <span class="pl-k">def</span> <span class="pl-en">single</span>():
    <span class="pl-k">return</span> <span class="pl-s1">incorrect_response</span>


<span class="pl-en">@<span class="pl-s1">pytest</span>.<span class="pl-s1">fixture</span></span>
<span class="pl-k">async</span> <span class="pl-k">def</span> <span class="pl-en">client</span>():
    <span class="pl-k">async</span> <span class="pl-k">with</span> <span class="pl-s1">httpx</span>.<span class="pl-v">AsyncClient</span>(<span class="pl-s1">app</span><span class="pl-c1">=</span><span class="pl-s1">app</span>, <span class="pl-s1">base_url</span><span class="pl-c1">=</span><span class="pl-s">"http://localhost"</span>) <span class="pl-k">as</span> <span class="pl-s1">client</span>:
        <span class="pl-k">yield</span> <span class="pl-s1">client</span>


<span class="pl-k">async</span> <span class="pl-k">def</span> <span class="pl-en">test_unprintable</span>(<span class="pl-s1">client</span>):
    <span class="pl-s1">res</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-s1">client</span>.<span class="pl-en">get</span>(<span class="pl-s">"/union"</span>)
    <span class="pl-k">assert</span> <span class="pl-s1">res</span>.<span class="pl-s1">status_code</span> <span class="pl-c1">==</span> <span class="pl-c1">400</span>


<span class="pl-k">async</span> <span class="pl-k">def</span> <span class="pl-en">test_400</span>(<span class="pl-s1">client</span>):
    <span class="pl-s1">res</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-s1">client</span>.<span class="pl-en">get</span>(<span class="pl-s">"/single"</span>)
    <span class="pl-k">assert</span> <span class="pl-s1">res</span>.<span class="pl-s1">status_code</span> <span class="pl-c1">==</span> <span class="pl-c1">400</span></pre></div>
<h3 dir="auto">Description</h3>
<p dir="auto">When <code class="notranslate">response_model</code> is set to a union of two possible models and I return something that does not match one of the two models, FastAPI returns a 500 error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="test_.py:30: in validation_exception_handler
    content=jsonable_encoder({&quot;detail&quot;: exc.errors()}),
../../../../../Library/Caches/pypoetry/virtualenvs/bla/lib/python3.9/site-packages/pydantic/error_wrappers.py:63: in errors
    config = self.model.__pydantic_model__.__config__  # type: ignore
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = typing.Union[tests.test_.ResponseOne, tests.test_.ResponseTwo]
attr = '__pydantic_model__'

    def __getattr__(self, attr):
        # We are careful for copy and pickle.
        # Also for simplicity we just don't relay all dunder names
        if '__origin__' in self.__dict__ and not _is_dunder(attr):
            return getattr(self.__origin__, attr)
&gt;       raise AttributeError(attr)
E       AttributeError: __pydantic_model__

../../../../../.pyenv/versions/3.9.9/lib/python3.9/typing.py:710: AttributeError"><pre class="notranslate"><code class="notranslate">test_.py:30: in validation_exception_handler
    content=jsonable_encoder({"detail": exc.errors()}),
../../../../../Library/Caches/pypoetry/virtualenvs/bla/lib/python3.9/site-packages/pydantic/error_wrappers.py:63: in errors
    config = self.model.__pydantic_model__.__config__  # type: ignore
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = typing.Union[tests.test_.ResponseOne, tests.test_.ResponseTwo]
attr = '__pydantic_model__'

    def __getattr__(self, attr):
        # We are careful for copy and pickle.
        # Also for simplicity we just don't relay all dunder names
        if '__origin__' in self.__dict__ and not _is_dunder(attr):
            return getattr(self.__origin__, attr)
&gt;       raise AttributeError(attr)
E       AttributeError: __pydantic_model__

../../../../../.pyenv/versions/3.9.9/lib/python3.9/typing.py:710: AttributeError
</code></pre></div>
<h3 dir="auto">Operating System</h3>
<p dir="auto">macOS</p>
<h3 dir="auto">Operating System Details</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">FastAPI Version</h3>
<p dir="auto">0.81.0</p>
<h3 dir="auto">Python Version</h3>
<p dir="auto">3.9.9</p>
<h3 dir="auto">Additional Context</h3>
<p dir="auto">It also does not work in FastAPI 0.7* and the pydantic version (1.9 vs 1.0) has no influence, either.</p>
<h3 dir="auto">First Check</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I added a very descriptive title to this issue.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I used the GitHub search to find a similar issue and didn't find it.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I searched the FastAPI documentation, with the integrated search.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already searched in Google "How to X in FastAPI" and didn't find any information.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already read and followed all the tutorial in the docs and didn't find an answer.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already checked if it is not related to FastAPI but to <a href="https://github.com/samuelcolvin/pydantic">Pydantic</a>.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already checked if it is not related to FastAPI but to <a href="https://github.com/swagger-api/swagger-ui">Swagger UI</a>.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already checked if it is not related to FastAPI but to <a href="https://github.com/Redocly/redoc">ReDoc</a>.</li>
</ul>
<h3 dir="auto">Commit to Help</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I commit to help with one of those options <g-emoji class="g-emoji" alias="point_up_2" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f446.png">👆</g-emoji></li>
</ul>
<h3 dir="auto">Example Code</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import uvicorn
from typing import Union

from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from pydantic import BaseModel

app = FastAPI()


class BaseItem(BaseModel):
    name: str
    type: str


class MyItem(BaseModel):
    foo: str
    num_foo: int
    bar: str
    num_bar: int


items = [ 
    {&quot;name&quot;: &quot;kitty&quot;, &quot;type&quot;: &quot;cat&quot;},
    {
        &quot;foo&quot;: &quot;foo&quot;, 
        &quot;num_foo&quot;: &quot;???&quot;, # &lt;-- Validation will FAIL !
        &quot;bar&quot;: &quot;bar&quot;, 
        &quot;num_bar&quot;:&quot;???&quot; # &lt;-- Validation will FAIL !
    }
]

@app.middleware('http')
async def exception_handler(request: Request, call_next):
    try:
        response = await call_next(request)
    except ValueError as ve:
        print(ve.raw_errors)
        errors = ve.errors()  # &lt;-- This raises AttributeError: __pydantic_model__ 
                              #     on 'http://localhost:8000/items_union_model/1'
        return JSONResponse(content=errors)
    return response

@app.get(&quot;/items_single_model/{item_id}&quot;, response_model=MyItem)
async def read_item_single_model(item_id: int):
    return items[item_id]

@app.get(&quot;/items_union_model/{item_id}&quot;, response_model=Union[BaseItem, MyItem])  #  &lt;-- Union type
async def read_item_union_model(item_id: int):
    return items[item_id]

if __name__ == '__main__':
    uvicorn.run(app, host='0.0.0.0')"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">uvicorn</span>
<span class="pl-k">from</span> <span class="pl-s1">typing</span> <span class="pl-k">import</span> <span class="pl-v">Union</span>

<span class="pl-k">from</span> <span class="pl-s1">fastapi</span> <span class="pl-k">import</span> <span class="pl-v">FastAPI</span>, <span class="pl-v">Request</span>
<span class="pl-k">from</span> <span class="pl-s1">fastapi</span>.<span class="pl-s1">responses</span> <span class="pl-k">import</span> <span class="pl-v">JSONResponse</span>
<span class="pl-k">from</span> <span class="pl-s1">pydantic</span> <span class="pl-k">import</span> <span class="pl-v">BaseModel</span>

<span class="pl-s1">app</span> <span class="pl-c1">=</span> <span class="pl-v">FastAPI</span>()


<span class="pl-k">class</span> <span class="pl-v">BaseItem</span>(<span class="pl-v">BaseModel</span>):
    <span class="pl-s1">name</span>: <span class="pl-s1">str</span>
    <span class="pl-s1">type</span>: <span class="pl-s1">str</span>


<span class="pl-k">class</span> <span class="pl-v">MyItem</span>(<span class="pl-v">BaseModel</span>):
    <span class="pl-s1">foo</span>: <span class="pl-s1">str</span>
    <span class="pl-s1">num_foo</span>: <span class="pl-s1">int</span>
    <span class="pl-s1">bar</span>: <span class="pl-s1">str</span>
    <span class="pl-s1">num_bar</span>: <span class="pl-s1">int</span>


<span class="pl-s1">items</span> <span class="pl-c1">=</span> [ 
    {<span class="pl-s">"name"</span>: <span class="pl-s">"kitty"</span>, <span class="pl-s">"type"</span>: <span class="pl-s">"cat"</span>},
    {
        <span class="pl-s">"foo"</span>: <span class="pl-s">"foo"</span>, 
        <span class="pl-s">"num_foo"</span>: <span class="pl-s">"???"</span>, <span class="pl-c"># &lt;-- Validation will FAIL !</span>
        <span class="pl-s">"bar"</span>: <span class="pl-s">"bar"</span>, 
        <span class="pl-s">"num_bar"</span>:<span class="pl-s">"???"</span> <span class="pl-c"># &lt;-- Validation will FAIL !</span>
    }
]

<span class="pl-en">@<span class="pl-s1">app</span>.<span class="pl-en">middleware</span>(<span class="pl-s">'http'</span>)</span>
<span class="pl-k">async</span> <span class="pl-k">def</span> <span class="pl-en">exception_handler</span>(<span class="pl-s1">request</span>: <span class="pl-v">Request</span>, <span class="pl-s1">call_next</span>):
    <span class="pl-k">try</span>:
        <span class="pl-s1">response</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-en">call_next</span>(<span class="pl-s1">request</span>)
    <span class="pl-k">except</span> <span class="pl-v">ValueError</span> <span class="pl-k">as</span> <span class="pl-s1">ve</span>:
        <span class="pl-en">print</span>(<span class="pl-s1">ve</span>.<span class="pl-s1">raw_errors</span>)
        <span class="pl-s1">errors</span> <span class="pl-c1">=</span> <span class="pl-s1">ve</span>.<span class="pl-en">errors</span>()  <span class="pl-c"># &lt;-- This raises AttributeError: __pydantic_model__ </span>
                              <span class="pl-c">#     on 'http://localhost:8000/items_union_model/1'</span>
        <span class="pl-k">return</span> <span class="pl-v">JSONResponse</span>(<span class="pl-s1">content</span><span class="pl-c1">=</span><span class="pl-s1">errors</span>)
    <span class="pl-k">return</span> <span class="pl-s1">response</span>

<span class="pl-en">@<span class="pl-s1">app</span>.<span class="pl-en">get</span>(<span class="pl-s">"/items_single_model/{item_id}"</span>, <span class="pl-s1">response_model</span><span class="pl-c1">=</span><span class="pl-v">MyItem</span>)</span>
<span class="pl-k">async</span> <span class="pl-k">def</span> <span class="pl-en">read_item_single_model</span>(<span class="pl-s1">item_id</span>: <span class="pl-s1">int</span>):
    <span class="pl-k">return</span> <span class="pl-s1">items</span>[<span class="pl-s1">item_id</span>]

<span class="pl-en">@<span class="pl-s1">app</span>.<span class="pl-en">get</span>(<span class="pl-s">"/items_union_model/{item_id}"</span>, <span class="pl-s1">response_model</span><span class="pl-c1">=</span><span class="pl-v">Union</span>[<span class="pl-v">BaseItem</span>, <span class="pl-v">MyItem</span>])  <span class="pl-c">#  &lt;-- Union type</span></span>
<span class="pl-k">async</span> <span class="pl-k">def</span> <span class="pl-en">read_item_union_model</span>(<span class="pl-s1">item_id</span>: <span class="pl-s1">int</span>):
    <span class="pl-k">return</span> <span class="pl-s1">items</span>[<span class="pl-s1">item_id</span>]

<span class="pl-k">if</span> <span class="pl-s1">__name__</span> <span class="pl-c1">==</span> <span class="pl-s">'__main__'</span>:
    <span class="pl-s1">uvicorn</span>.<span class="pl-en">run</span>(<span class="pl-s1">app</span>, <span class="pl-s1">host</span><span class="pl-c1">=</span><span class="pl-s">'0.0.0.0'</span>)</pre></div>
<h3 dir="auto">Description</h3>
<h2 dir="auto">Summary</h2>
<ul dir="auto">
<li>When data validation using response_model fails due to wrong data, I want to return back the error list to the requester.
<ul dir="auto">
<li>I added <code class="notranslate">exception_handler</code> middleware to achieve this.</li>
</ul>
</li>
<li>This works perfectly when the response_model is a single class (derived from BaseModel of Pydantic)
<ul dir="auto">
<li>You can open <a href="http://localhost:8000/items_single_model/1" rel="nofollow">http://localhost:8000/items_single_model/1</a> from the browser.</li>
</ul>
</li>
<li>But when the response_model is <code class="notranslate">Union</code> type which is said to be supported by <a href="https://fastapi.tiangolo.com/tutorial/extra-models/?h=union#union-or-anyof" rel="nofollow">this example</a>
<ul dir="auto">
<li><code class="notranslate">AttributeError: __pydantic_model__</code> occurs when I call <code class="notranslate">ValidationError.errors()</code> method to get error information</li>
<li>You can open <a href="http://localhost:8000/items_union_model/1" rel="nofollow">http://localhost:8000/items_union_model/1</a> and see the server log.</li>
</ul>
</li>
<li>This could ultimately be a problem of Pydantic but the way passing the error data to Pydantic might be a problem</li>
</ul>
<p dir="auto">Is this expected behavior ? If so, How can I exact list or dict type of error data in this situation ?</p>
<h2 dir="auto">Traceback</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Traceback (most recent call last):
  File &quot;/home/jamie/.asdf/installs/python/3.8.10/lib/python3.8/site-packages/uvicorn/protocols/http/httptools_impl.py&quot;, line 398, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File &quot;/home/jamie/.asdf/installs/python/3.8.10/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py&quot;, line 45, in __call__
    return await self.app(scope, receive, send)
  File &quot;/home/jamie/.asdf/installs/python/3.8.10/lib/python3.8/site-packages/fastapi/applications.py&quot;, line 208, in __call__
    await super().__call__(scope, receive, send)
  File &quot;/home/jamie/.asdf/installs/python/3.8.10/lib/python3.8/site-packages/starlette/applications.py&quot;, line 112, in __call__
    await self.middleware_stack(scope, receive, send)
  File &quot;/home/jamie/.asdf/installs/python/3.8.10/lib/python3.8/site-packages/starlette/middleware/errors.py&quot;, line 181, in __call__
    raise exc from None
  File &quot;/home/jamie/.asdf/installs/python/3.8.10/lib/python3.8/site-packages/starlette/middleware/errors.py&quot;, line 159, in __call__
    await self.app(scope, receive, _send)
  File &quot;/home/jamie/.asdf/installs/python/3.8.10/lib/python3.8/site-packages/starlette/middleware/base.py&quot;, line 25, in __call__
    response = await self.dispatch_func(request, self.call_next)
  File &quot;./main.py&quot;, line 40, in exception_handler
    errors = ve.errors()  # &lt;-- This raises AttributeError: __pydantic_model__
  File &quot;pydantic/error_wrappers.py&quot;, line 52, in pydantic.error_wrappers.ValidationError.errors
  File &quot;/home/jamie/.asdf/installs/python/3.8.10/lib/python3.8/typing.py&quot;, line 760, in __getattr__
    raise AttributeError(attr)
AttributeError: __pydantic_model__"><pre class="notranslate"><code class="notranslate">Traceback (most recent call last):
  File "/home/jamie/.asdf/installs/python/3.8.10/lib/python3.8/site-packages/uvicorn/protocols/http/httptools_impl.py", line 398, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "/home/jamie/.asdf/installs/python/3.8.10/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
    return await self.app(scope, receive, send)
  File "/home/jamie/.asdf/installs/python/3.8.10/lib/python3.8/site-packages/fastapi/applications.py", line 208, in __call__
    await super().__call__(scope, receive, send)
  File "/home/jamie/.asdf/installs/python/3.8.10/lib/python3.8/site-packages/starlette/applications.py", line 112, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/jamie/.asdf/installs/python/3.8.10/lib/python3.8/site-packages/starlette/middleware/errors.py", line 181, in __call__
    raise exc from None
  File "/home/jamie/.asdf/installs/python/3.8.10/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in __call__
    await self.app(scope, receive, _send)
  File "/home/jamie/.asdf/installs/python/3.8.10/lib/python3.8/site-packages/starlette/middleware/base.py", line 25, in __call__
    response = await self.dispatch_func(request, self.call_next)
  File "./main.py", line 40, in exception_handler
    errors = ve.errors()  # &lt;-- This raises AttributeError: __pydantic_model__
  File "pydantic/error_wrappers.py", line 52, in pydantic.error_wrappers.ValidationError.errors
  File "/home/jamie/.asdf/installs/python/3.8.10/lib/python3.8/typing.py", line 760, in __getattr__
    raise AttributeError(attr)
AttributeError: __pydantic_model__
</code></pre></div>
<h3 dir="auto">Operating System</h3>
<p dir="auto">Linux</p>
<h3 dir="auto">Operating System Details</h3>
<p dir="auto">Ubuntu 20.04 (under Windows 10 WSL2)</p>
<h3 dir="auto">FastAPI Version</h3>
<p dir="auto">0.68.0</p>
<h3 dir="auto">Python Version</h3>
<p dir="auto">3.8.10</p>
<h3 dir="auto">Additional Context</h3>
<p dir="auto">Pydantic version: 1.8.2</p>