# Getting user by ID

* The path operation should never return the password

```python
@app.get("/users/{id}", response_model=schemas.UserOut)
def get_user(id: int, db: Session = Depends(get_db)):

    user = db.query(models.User).filter(models.User.id == id).first()

    if not user:
        raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"User with id: {id} does not exist")

    return user
```

* It will return the user without the password because of the <mark style="color:orange;">`response_model`</mark>
* The user will be searched by ID in the database
* If this is not found, it will raise a HTTP404
* If it does find it, it will return the ID, email, and created\_at field

```json
{
    "id": 5,
    "email": "123@gmail.com",
    "created_at": "2022-07-29T10:06:18.287097+03:00"
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.arkannis.net/programming/python/frameworks/fastapi/getting-user-by-id.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
