-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Summary
Add support for default values on QType variables to improve UX when variables have sensible defaults that users may want to override.
Motivation
Currently, QType variables cannot have default values. This means:
- All inputs must be provided explicitly, even when there's a sensible default
- Workarounds like PromptTemplate steps are needed to set defaults
- Optional variables (
type: text?) can be null but can't have a fallback value
Real-World Use Case
We want users to provide a custom analysis prompt but have a reasonable default if they don't:
variables:
- id: analysis_prompt
type: text
ui:
widget: textarea
# Would like: default: "Analyze the following data and provide insights..."Without defaults, users must either:
- Always provide the value (poor UX)
- Make it optional and handle None in steps (requires extra logic)
- Add a PromptTemplate step just to set a default (verbose)
Proposed Solution
Add a default field to the Variable schema:
variables:
- id: analysis_prompt
type: text
default: "Analyze this data and provide key insights"
- id: temperature
type: float
default: 0.7
- id: max_tokens
type: int
default: 2000Behavior
- If a variable has a
defaultand no value is provided at runtime, use the default - If a value is provided at runtime, use the provided value (overrides default)
- Default values should be validated against the variable's type
- Default values work with all types (text, int, float, bool, lists, custom types)
Implementation Considerations
Schema Changes
Add default field to Variable model:
class Variable(StrictBaseModel):
id: str
type: str | Type
optional: bool = False
default: Any | None = None
ui: TextInputUI | FileUploadUI | None = NoneValidation
- Validate that
defaultmatches the variable'stype - Consider: Should
optional=Trueanddefaultbe mutually exclusive? Or can a variable have both?- If both allowed: when value is None, should we use default or keep None?
- Recommendation: Allow both - use default when value is missing/None
Runtime Behavior
When executing a flow:
- Check if variable has a value in inputs
- If not, check if variable has a default
- If not, raise error (unless optional=True)
UI Integration
- The QType UI should show default values as placeholders in input fields
- Consider showing a "Reset to default" button
- Display the default value in the flow's input documentation
Examples
Simple Defaults
flows:
- id: llm_chat
variables:
- id: prompt
type: text
- id: temperature
type: float
default: 0.7
- id: max_tokens
type: int
default: 2000Complex Defaults with UI Hints
flows:
- id: analysis
variables:
- id: data_source
type: text
- id: custom_instructions
type: text
default: |
Please analyze the data and provide:
1. Key trends
2. Notable anomalies
3. Actionable recommendations
ui:
widget: textareaDefault with Optional
variables:
- id: api_key
type: text?
default: null # Optional, defaults to null if not providedBenefits
- Better UX - Users can run flows with sensible defaults
- Less boilerplate - No need for initialization steps just to set defaults
- Self-documenting - Defaults show expected values
- Flexibility - Users can still override when needed
Testing Requirements
- Unit tests for default value validation
- Integration tests for flow execution with defaults
- Test defaults with all primitive types
- Test defaults with custom types
- Test interaction between
defaultandoptional - Test UI rendering of defaults
Related Issues
- Add Dict-Style Syntax for Tool and Flow Variables #124 - Dict-style variable syntax (complementary feature)
Questions
- Should serialization preserve default values when generating YAML?
- Should defaults be allowed for output variables, or only inputs?
- Should defaults work with references (e.g.,
client: client_namewith default)?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request