From 82e8c80b8c15149dc425e8b97f9ef426b2a50605 Mon Sep 17 00:00:00 2001 From: vikram Date: Sun, 19 Apr 2026 03:05:50 +0530 Subject: [PATCH] Improve clarity on path parameter type conversion --- docs/en/docs/tutorial/path-params.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/en/docs/tutorial/path-params.md b/docs/en/docs/tutorial/path-params.md index 6614dfdcb7..d364f9eaee 100644 --- a/docs/en/docs/tutorial/path-params.md +++ b/docs/en/docs/tutorial/path-params.md @@ -12,6 +12,18 @@ So, if you run this example and go to [http://127.0.0.1:8000/items/foo](http://1 {"item_id":"foo"} ``` +/// note + +Path parameters are always received as strings from the URL. + +Without a type annotation, `item_id` will be treated as a `str`. +By adding a type (e.g. `int`), **FastAPI** will automatically: +- convert the value to the correct type +- validate the input +- return an error if the conversion fails + +/// + ## Path parameters with types { #path-parameters-with-types } You can declare the type of a path parameter in the function, using standard Python type annotations: