fal Applications are fully compatible with Pydantic. Any features of Pydantic used in fal endpoint arguments will also work, and you may use Pydantic features for data validation in your endpoint.
Although, in order for your inputs and outputs to be nicely rendered in the playground, you need to use certain conventions that tell our frontend how to interpret the data.
For the best experience defining inputs and outputs, use FalBaseModel from the fal SDK. It extends Pydantic’s BaseModel with features specifically designed for fal applications:
Field ordering - Control the order fields appear in the playground and API schema
Hidden fields - Mark parameters as API-only, hiding them from the playground and API schema.
Report incorrect code
Copy
from fal.toolkit import FalBaseModel, Field, Hiddenclass TextToImageInput(FalBaseModel): FIELD_ORDERS = ["prompt", "negative_prompt", "image_size"] prompt: str = Field(description="Text description of the image") negative_prompt: str = Field(default="", description="What to avoid") image_size: str = Field(default="1024x1024", description="Output dimensions") # Hidden from playground UI but accessible via API debug_mode: bool = Hidden(Field(default=False)) internal_seed: int = Hidden(Field(default=-1))
Use the FIELD_ORDERS class variable to control the order fields appear in the API schema and playground. Fields listed in FIELD_ORDERS appear first, in the specified order, followed by any remaining fields.This is particularly useful when you have a base model with common fields that multiple models inherit from. By default, Pydantic places child class fields before parent class fields in the schema. FIELD_ORDERS lets you ensure base model fields (like prompt) appear first for a consistent user experience.
Report incorrect code
Copy
from fal.toolkit import FalBaseModel, Field, ImageField# Base model with common fieldsclass BaseTextInput(FalBaseModel): FIELD_ORDERS = ["prompt", "negative_prompt"] prompt: str = Field(description="Text prompt") negative_prompt: str = Field(default="", description="What to avoid")# Extended model for image-to-imageclass ImageToImageInput(BaseTextInput): # Override FIELD_ORDERS to control the full order FIELD_ORDERS = ["prompt", "negative_prompt", "image_url", "strength"] image_url: str = ImageField(description="Input image") strength: float = Field(default=0.8, description="How much to transform")# Without FIELD_ORDERS, schema would show: image_url, strength, prompt, negative_prompt# With FIELD_ORDERS, schema shows: prompt, negative_prompt, image_url, strength
For better playground rendering, use the specialized field helpers instead of plain Field():
Helper
UI Rendering
FileField(...)
Generic file upload
ImageField(...)
Image upload/preview
AudioField(...)
Audio upload/player
VideoField(...)
Video upload/player
Report incorrect code
Copy
from fal.toolkit import FalBaseModel, ImageField, AudioFieldclass MyInput(FalBaseModel): # Renders as image upload in playground input_image: str = ImageField(description="Source image") # Renders as audio upload in playground voice_sample: str = AudioField(description="Voice sample for cloning")
These helpers work with both Pydantic v1 and v2. See the Standard Inputs and Outputs section below for more details on each media type, including naming conventions and output handling.