---
title: "💭 Fields - Pydantic"
description: "!https://docs.pydantic.dev/2.7/concepts/fields/#field-representation"
date: 2024-05-09
published: true
tags:
  - pydantic
  - fastapi
  - webdev
  - thought
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'
```

!!! note

    This post is a <a href="/thoughts/" class="wikilink" data-title="Thoughts" data-description="These are generally my thoughts on a web page or some sort of url, except a rare few don&#39;t have a link. These are dual published off of my..." data-date="2024-04-01">thought</a>. It's a short note that I make
    about someone else's content online <a href="/tags/thoughts/" class="hashtag-tag" data-tag="thoughts" data-count=2 data-reading-time=3 data-reading-time-text="3 minutes">#thoughts</a>
