# Early Exit

When writing a workflow step program and you need to exit the workflow early because a pre-condition is not met, use the keyword `lam.exit` in your return object.

**Example:** Using our order fulfillment workflow example from [Getting Started](/getting-started.md), suppose we needed to check that incoming order is not for a digital service before proceeding to send data to fulfillment centre.

{% stepper %}
{% step %}

### Send Orders to Fulfillment Centre

```diff
(data) => {
    const inputOrder = data.input;
    
+   if (inputOrder.isDigital) {
+       return {
+         "lam.exit": true,
+         // payload to be returned
+         "data": { 
+           "message": "Skipped. Digital service orders should not be sent to fulfillment centre.",
+           "order": inputOrder,
+         }
+       };
+   }

    // Use Array.map to transform the items array
    const transformedItems = inputOrder.items.map(item => ({
        sku: item.product.sku,
        name: item.product.name,
        quantity: item.quantity,
        price: parseFloat(item.price) // Convert price from string to number
    }));

    // Construct the final output object
    const outputOrder = {
        customer_name: inputOrder.customerName,
        customer_email: inputOrder.customerEmail,
        customer_phone: "+1234567890", // Placeholder as source data is missing
        shipping_address: {
            street: `${inputOrder.shippingAddressLine1 || ''} ${inputOrder.shippingAddressLine2 || ''}`.trim(),
            city: inputOrder.shippingCity,
            state: inputOrder.shippingState,
            zip: inputOrder.shippingZipCode,
            country: inputOrder.shippingCountry
        },
        items: transformedItems,
        shipping_method: "standard" // Default value as source data is missing
    };

    return outputOrder;
}
```

{% endstep %}

{% step %}

### ...

{% endstep %}
{% endstepper %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.laminar.run/advanced/early-exit.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
