AIML Docs

Else Element

Element for default execution path

Else Element

Coming soon: This feature is not yet available. Please check back soon.

The <else> element provides a default execution path when no other conditions match:

<if condition={({state}) => state.count > 10}>
<llm>
  <prompt>Count is greater than 10</prompt>
</llm>
</if>
<elseif condition={({state}) => state.count > 5}>
<llm>
  <prompt>Count is greater than 5</prompt>
</llm>
</elseif>
<else>
<llm>
  <prompt>Count is 5 or less</prompt>
</llm>
</else>

Props

PropTypeDefault
id?
string
-

Examples

Basic Default Case

<if condition={({state}) => state.isValid}>
<assign location="state.status" expr="valid" />
</if>
<else>
<assign location="state.status" expr="invalid" />
</else>

Error Handling

<if condition={({state}) => state.data !== null}>
<script>processData(state.data);</script>
</if>
<else>
<assign location="state.error" expr="Data is null" />
<log expr="Data is null" />
</else>

Complex Flow

<if condition={({state}) => state.userRole === "admin"}>
<assign location="state.access" expr="full" />
</if>
<elseif condition={({state}) => state.userRole === "editor"}>
<assign location="state.access" expr="write" />
</elseif>
<else>
<assign location="state.access" expr="read" />
<assign location="state.accessLevel" expr="limited" />
</else>

Usage Notes

  • Must follow an <if> element or <elseif> element
  • Represents the final branch in a conditional chain
  • Executes when no previous conditions match
  • Can contain any executable content

Common Patterns

Default Assignment

<if condition={({state}) => state.value > 0}>
<assign location="state.status" expr="positive" />
</if>
<else>
<assign location="state.status" expr="non-positive" />
</else>

Error Recovery

<if condition={({state}) => state.isValid}>
<transition target="processData" />
</if>
<else>
<log expr="Invalid state detected" />
<assign location="state.error" expr="Validation failed" />
<transition target="errorHandler" />
</else>

Default Response

<if condition={({state}) => state.hasCustomResponse}>
<llm>
  <prompt>{({state}) => state.customResponse}</prompt>
</llm>
</if>
<else>
<llm>
  <prompt>I'm sorry, I don't have a specific response for that.</prompt>
</llm>
</else>

On this page