Use {py:class}~nat.data_models.gated_field_mixin.GatedFieldMixin to gate configuration fields based on whether an analyzed field supports them. This enables provider-agnostic, model-aware validation with sensible defaults and clear errors.
- Detection keys: The mixin scans
keysspecified on the instance to identify values used to determine if the field is supported. - Selection modes: Provide exactly one of the following when subclassing:
unsupported: A sequence of compiled regex patterns that mark the detector field where the mixin's field is not supported.supported: A sequence of compiled regex patterns that mark the detector field where the mixin's field is supported.
- Behavior:
- Supported and value not provided → sets
default_if_supported. - Supported and value provided → keeps the provided value (and performs all other validations if defined).
- Unsupported and value provided → raises a validation error.
- Unsupported and value not provided → leaves the field as
None. - No detection keys present → applies
default_if_supported.
- Supported and value not provided → sets
import re
from pydantic import BaseModel, Field
from nat.data_models.gated_field_mixin import GatedFieldMixin
class FrequencyPenaltyMixin(
BaseModel,
GatedFieldMixin,
field_name="frequency_penalty",
default_if_supported=0.0,
keys=("model_name", "model", "azure_deployment"),
supported=(re.compile(r"^gpt-4.*$", re.IGNORECASE),),
):
frequency_penalty: float | None = Field(default=None, ge=0.0, le=2.0)class AzureOnlyMixin(
BaseModel,
GatedFieldMixin,
field_name="some_param",
default_if_supported=1,
keys=("azure_deployment",),
unsupported=(re.compile(r"gpt-?5", re.IGNORECASE),),
):
some_param: int | None = Field(default=None)
azure_deployment: str- {py:class}
~nat.data_models.thinking_mixin.ThinkingMixin- Field:
thinking: bool | None - Default when supported:
None(use model default) - Only currently supported on Nemotron models
- Field:
- Use
supportedfor allowlist andunsupportedfor denylist; do not set both. - Keep regex patterns specific (anchor with
^and$when appropriate). - If your config uses a non-standard model identifier field, set
keysaccordingly.