# Fix "ValueError: 'not' is not a valid parameter name" in a FastAPI App on Python 3.11 or Later

Yes. An agent traces the error to an old pydantic 1.x pin, raises it to a release that imports on your Python, and runs the tests on old and new interpreters.

[Run this on Rush](https://cloud.getrush.ai/run/fix-not-is-not-a-valid-parameter-name/pydantic/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The error has nothing to do with a parameter you wrote. It is raised while FastAPI is being imported. FastAPI's own OpenAPI models contain a field declared as `not_: Optional[Any] = Field(None, alias="not")`, because `not` is a keyword in JSON Schema. Old pydantic 1.x releases build a call signature for every model from its aliases, by creating an `inspect.Parameter` for each one, and from Python 3.11 `inspect.Parameter` refuses a name that is a Python keyword. The traceback runs from `fastapi/openapi/models.py` through `generate_model_signature` in `pydantic/utils.py` into `inspect.py`, and none of its frames are in your project.

a-luna/fastapi-redis-cache, a caching decorator for FastAPI endpoints, has the pins that produce it. `requirements.txt` holds `fastapi==0.65.2` and `pydantic==1.8.2`. Everything else in the repository says Python 3.7 to 3.9: the matrix in `.github/workflows/tox.yml`, the `envlist` in `tox.ini`, the classifiers in `setup.py`. So the project was never tested on the interpreters where the import fails. The agent installs the two pins on Python 3.10, where `import fastapi` succeeds, and on 3.11, 3.12 and 3.13, where it raises the `ValueError`, and keeps the four results as the reproduction.

It then finds the smallest change that works. FastAPI 0.65.2 declares `pydantic >=1.6.2, <2.0.0` with a few early releases excluded, so any later 1.x release satisfies it. Moving to pydantic 1.9.2 does not help; the error is the same. Pydantic 1.10.2 and the later 1.10 releases import cleanly on 3.12 and 3.13 with FastAPI left at 0.65.2, and a small app built on that pair can generate its OpenAPI document, which exercises the models that failed. The agent changes one line of `requirements.txt` to the newest 1.10 release and leaves `fastapi`, `redis` and `uvicorn` alone.

The rest of the work is proving it and making it stay proven. The agent runs `pytest` against `tests/test_cache.py`, which drives the app in `tests/main.py` through FastAPI's test client with `CACHE_ENV=TEST`, the switch in `src/fastapi_redis_cache/redis.py` that swaps in `FakeRedis`, so no Redis server is needed. It runs the suite on an old interpreter and a new one. It adds the newer Pythons to the workflow matrix and to `tox.ini`, and reports separately on the development pins in `requirements-dev.txt`, which are from the same period and may need their own updates before the formatting and lint steps in tox run on a new interpreter. A move to pydantic 2 and current FastAPI is described as a follow-up, not folded in.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Importing FastAPI in this project fails with \"ValueError: 'not' is not a valid parameter name\" on Python 3.11 or later. Reproduce it: install the pinned requirements on Python 3.10 and on each of 3.11, 3.12 and 3.13, run python -c \"import fastapi\" on each, and record which succeed and the full traceback where it fails. Read the requirements files, setup.py or pyproject.toml, tox.ini and the CI workflows, and report the pinned fastapi and pydantic versions and which Python versions the project claims and tests. Read the installed fastapi's metadata to see which pydantic range it accepts. Find the smallest change that makes the import work on every interpreter: try later pydantic 1.x releases inside that range before touching fastapi, and say which ones you tried and what each did. Apply that change only. Then run the test suite on the oldest Python the project supports that you can install and on the newest, using whatever fake or in-memory backends the tests already provide, and do not start external services. Add the newer Python versions to the CI matrix and tox environments, and fix or report any development tool pins that stop the test run on them. Do not migrate to pydantic 2 in this change; describe what that migration would involve in the pull request instead. Open a pull request with the import results per interpreter before and after, the versions you tried, and the test output.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

A pull request whose essential change is one pin. Around it are the additions that keep the fix honest: the extra interpreters in the workflow matrix and `tox.ini`, and the updated classifiers if the project publishes them. The description has a grid of interpreter against pydantic version, with import result in each cell, before and after, followed by the test output on the oldest and newest Python the agent ran.

A reviewer confirms that the new pydantic version is still inside the range the pinned FastAPI declares, so the two were meant to work together and are not merely installable. They check that no model code in their own application relied on behaviour that changed between pydantic 1.8 and 1.10; the test run is the evidence for that, and its coverage is theirs to judge. If lint or formatting steps fail on the new interpreters for reasons unrelated to pydantic, the description lists them with the failing command, and the reviewer can take them in a second pull request.

## Run it on every new Python release

Each new interpreter can break an old pin in the same way, and services that share a template usually share the pin. When your base image or runtime moves to a new Python, send the request above once per service from a small script, with the `resources` URL changed each time. Runs beyond the key's concurrency limit are created `queued` and start as earlier ones finish. Set a `webhook_url` on the key and your server receives `run.completed` for each, with the session to read the pull request from.

To make it routine, give each Project an automation with a `schedule` trigger and a monthly `cron`, and a prompt that installs the pinned requirements on the newest released Python, imports the application and reports or fixes what fails. In most months it finds nothing and opens no pull request.

## Why run it on Rush?

The answer depends on a grid: several Python versions against several pydantic releases. A laptop has one or two interpreters, and trying a release means reinstalling into the environment you work in. The agent installs each interpreter into its sandbox, builds a fresh environment per cell and runs the import in each, so the pull request can say which combinations work because it tried them. The commands and their output are kept in the session transcript.

The change it proposes is also deliberately narrow. The usual advice for this error is to upgrade FastAPI and pydantic together, which for a codebase on pydantic 1 means a migration to version 2. That may be the right long-term move, but it is not required to start the app on a new Python. The run finds the one-line fix first and describes the larger change separately, so you can schedule it instead of being forced into it by a runtime upgrade.

## Frequently asked questions

### I have no parameter named 'not'. Where does the name come from?

From FastAPI's models for the OpenAPI schema. JSON Schema has a keyword called `not`, and FastAPI declares it as a field `not_` with the alias `"not"`. Old pydantic 1.x releases used the alias as a parameter name when building the model's signature, and newer Pythons reject keywords there.

### Do I have to move to pydantic 2 to fix this?

No. A later pydantic 1.10 release fixes it and stays inside the `<2.0.0` range that old FastAPI versions require. Moving to pydantic 2 also means a newer FastAPI and changes to your models, which is a separate piece of work.

### Why does it work on Python 3.10 and fail on 3.11?

Because `inspect.Parameter` changed. On 3.10 it accepts `not` as a parameter name; from 3.11 it raises `ValueError` for any Python keyword. The pinned libraries did not change, only the interpreter under them.

### The error appears while importing a different library, not FastAPI. Is the fix the same?

Usually. Any pydantic model with a field aliased to a Python keyword, such as `not`, `in` or `class`, triggers it on an old pydantic 1.x. The agent reads the traceback to find which package defines the model and checks that package's declared pydantic range before changing the pin.

## More Pydantic jobs

- [Fix 'orm_mode' Has Been Renamed to 'from_attributes' in a FastAPI App](https://getrush.ai/run/fix-orm-mode-has-been-renamed-to-from-attributes/pydantic/)
- [Fix "PydanticImportError: BaseSettings has been moved to the pydantic-settings package"](https://getrush.ai/run/fix-pydantic-basesettings-import-error/pydantic/)
- [Fix "PydanticUserError: `regex` is removed. use `pattern` instead" in Pydantic 2](https://getrush.ai/run/fix-pydantic-regex-is-removed/pydantic/)

## More jobs like this: Fix a bug from an alert

- [Fix "np.alltrue was removed in the NumPy 2.0 release"](https://getrush.ai/run/fix-np-alltrue-was-removed-in-the-numpy-2-release/numpy/)
- [Fix "ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject"](https://getrush.ai/run/fix-numpy-dtype-size-changed/numpy/)
- [Fix "AttributeError: module 'numpy' has no attribute 'float'" on NumPy 1.24 and Later](https://getrush.ai/run/fix-numpy-float-attribute-error/numpy/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
