Kyle McChesney
02/17/2026, 9:58 PM3.0, 10.0, etc. The UI and the API seem to auto-magically convert these fields back to integers (3, 10, etc). This causes flickering with the terraform provider.Marvin
02/17/2026, 9:58 PMMarvin
02/17/2026, 10:07 PMfrom pydantic import BaseModel, Field, field_validator
class Params(BaseModel):
rate: str = Field("3.0")
# ... repeat for other fields
@field_validator("rate", mode="before")
def coerce_to_canonical_float_string(cls, v):
# Accept numbers or strings, emit canonical string with one decimal
if isinstance(v, (int, float)):
return f"{float(v):.1f}"
# If already a string like "3" or "3.0", normalize it
try:
return f"{float(v):.1f}"
except Exception:
return v
Then in your flow, cast to float when you use it: float(params.rate).
- Alternative: Use Decimal and force string serialization. This also preserves formatting but will show as a string field in the UI:
from decimal import Decimal
from pydantic import BaseModel, Field, field_serializer
class Params(BaseModel):
rate: Decimal = Field(default=Decimal("3.0"))
@field_serializer("rate", when_used="json")
def ser_rate(self, v: Decimal) -> str:
return format(v, "f") # "3.0"
Notes
- Keeping these as numeric fields while guaranteeing “3.0” instead of “3” is not feasible with JSON/JS semantics; the UI (and many JSON encoders) will normalize to a canonical number representation.
- If this drift is coming specifically from the Prefect Terraform provider, you may want to open an issue asking it to treat 3 and 3.0 as equivalent to avoid plan flicker. Provider link: Terraform Registry: Prefect Provider. Repo (for issues): PrefectHQ/terraform-provider-prefect.
If you can share:
- The provider version
- A minimal example of your Pydantic model and the exact Terraform diff
…I’m happy to try to reproduce and suggest the least invasive fix for your setup.
Docs for reference:
- Prefect parameters overview: Parameters in Prefect
- Pydantic v2 JSON schema/serialization background: Pydantic JSON Schema and Serialization