Comments & Descriptions¶
Proto file comments are preserved in the generated Python output in two ways:
- Message / enum comments → Python docstrings
- Field comments → inline
# comment+Field(description=...)
Message docstrings¶
Leading comments on a message become its Python docstring:
Field descriptions¶
Field comments become both an inline Python comment and a description= argument on _Field():
The description= value is visible to downstream tools that consume Pydantic's JSON Schema,
such as FastAPI / Swagger UI.
Disabling field descriptions¶
If you want to omit the description= argument (e.g. to keep generated files smaller),
use disable_field_description=true:
# buf.gen.yaml
plugins:
- local: protoc-gen-pydantic
opt:
- paths=source_relative
- disable_field_description=true
out: gen
With this option the inline comment is still emitted, but Field() has no description=:
Enum docstrings¶
Leading comments on enum types and values are preserved the same way: