Use the <If>
, <ElseIf>
, and <Else>
tags for conditional rendering:
---
name: greeting
text_config:
model_name: gpt-4
test_settings:
props:
userType: "admin"
---
<System>
<If condition={props.userType == "admin"}>
You should provide detailed technical information when asked.
</If>
<ElseIf condition={props.userType == "developer"}>
You should provide code examples when asked.
</ElseIf>
<Else>
You should provide simple explanations.
</Else>
</System>
<User>Tell me about databases.</User>
Logical Operators
You can use standard JavaScript logical operators (&&
, ||
, !
) in your conditions:
language-response.prompt.mdx
---
name: language-response
text_config:
model_name: gpt-4
test_settings:
props:
isAdmin: true
hasTechnicalBackground: true
---
<System>
<If condition={props.isAdmin && props.hasTechnicalBackground}>
Include implementation details and system architecture in your responses.
</If>
<ElseIf condition={props.isAdmin || props.hasTechnicalBackground}>
Include technical details but avoid implementation specifics.
</ElseIf>
<Else>
Keep explanations simple and non-technical.
</Else>
</System>
Nested Conditionals
Conditionals can be nested for more complex logic:
nested-conditions.prompt.mdx
---
name: nested-conditions
text_config:
model_name: gpt-4
test_settings:
props:
userLevel: "expert"
language: "Spanish"
---
<System>
<If condition={props.userLevel == "expert"}>
<If condition={props.language == "Spanish"}>
Respond with technical Spanish and include English translations.
</If>
<Else>
Respond with technical English.
</Else>
</If>
<Else>
<If condition={props.language == "Spanish"}>
Respond with simple Spanish and include English translations.
</If>
<Else>
Respond with simple English.
</Else>
</If>
</System>
Best Practices
- Keep conditions simple and readable
- Use meaningful variable names in conditions
- Consider breaking complex conditional logic into separate components
- Test different condition branches using test_settings
Have Questions?
We’re here to help! Choose the best way to reach us: