> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bondata.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Head/Tail

> Limit the dataset to the first or last N records

Keeps only the first N or last N records from the dataset. Use it after sorting to get "top N" results, or to limit the size of data flowing downstream.

## Configuration

| Setting   | Description                                                       |
| --------- | ----------------------------------------------------------------- |
| **Value** | Number of records to keep (must be greater than 0)                |
| **Mode**  | **Head** (first N records - default) or **Tail** (last N records) |

## How It Works

<Steps>
  <Step title="Set the limit">
    Enter the number of records to keep.
  </Step>

  <Step title="Choose mode">
    Select **Head** for the first N records or **Tail** for the last N.
  </Step>
</Steps>

## Output

The first or last N records from the input. If the dataset has fewer records than the specified value, all records are kept.

## Example

Get the top 10 accounts by revenue:

1. **Sort** → Revenue (descending)
2. **Head/Tail** → Value: 10, Mode: Head

Result: only the 10 highest-revenue accounts flow downstream.

## Best Practices

* Always **Sort** before Head/Tail if the order matters - without sorting, Head/Tail returns arbitrary records
* Use Head to sample data during testing (e.g., limit to 5 records before an AI Enrichment node)
* Use Tail to get the most recent records when data is sorted by date

## Related Nodes

* **[Sort](/guide/nodes/transform/sort-node)** - order records before limiting with Head/Tail
* **[Simple Filter](/guide/nodes/filter/simple-filter-node)** - filter by conditions rather than position
