---
title: "Fields - Pydantic"
description: "!https://docs.pydantic.dev/2.7/concepts/fields/#field-representation"
date: 2024-05-10
published: true
tags:
  - dev
  - fastapi
  - pydantic
  - python
  - thought
  - webdev
template: link
---


<div class="embed-card embed-card-external">
  <a href="https://docs.pydantic.dev/2.7/concepts/fields/#field-representation" class="embed-card-link" target="_blank" rel="noopener noreferrer">
    <div class="embed-card-image">
      <img src="https://pydantic.dev/docs/og/validation/2.7/concepts/fields.png" alt="Fields" loading="lazy">
    </div>
    <div class="embed-card-content">
      <div class="embed-card-title">Fields</div>
      <div class="embed-card-meta">Pydantic Docs &middot; docs.pydantic.dev</div>
    </div>
  </a>
</div>


`exclude=True` and `repr=False` is a good pydantic combination for secret attributes such as user passwords, or hashed passwords.  exclude keeps it out of model_dumps, and repr keeps it out of the logs.

``` python
from pydantic import BaseModel, Field


class User(BaseModel):
    name: str = Field(repr=True)  
    age: int = Field(repr=False)


user = User(name='John', age=42)
print(user)
#> name='John'
```
