> For the complete documentation index, see [llms.txt](https://docs.unitlab.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.unitlab.ai/api-sdk-cli/sdks/data-group-automation.md).

# Data Group automation

### The product state this automation creates

![Auto-Groups custom layout editor](https://292810646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGjVLUz4wthGkGlRKM6rM%2Fuploads%2F8eyEMKLe8RbL8q4uIsNW%2Fauto-groups-custom-layout.png?alt=media\&token=810552ad-bdf3-44b8-b959-3f3afe77847d)

*The SDK grouping configuration controls the same grouping keys, completeness rules, tile identities, and saved Grid, List, or Custom layout exposed by the Auto-Groups wizard.*

{% hint style="info" %}
**Outcome:** Suggest, estimate, and create Data Groups from a folder with explicit grouping configuration.
{% endhint %}

```python
folder = client.assets.folder("FOLDER_ID")
suggestion = folder.suggest_grouping()

config = {
    "group_by": "study_id",
    "layout": {"columns": 2, "rows": 2},
}
print(folder.estimate_grouping(config))
result = folder.auto_group(config)
print(result.group_count, result.grouped_folder().id)
```

Use `suggest_grouping()` to inspect a proposed strategy and `estimate_grouping(config)` to preview its effect. `auto_group()` creates groups and returns a `GroupingResult`. Validate incomplete and ambiguous groups before attaching the result to production work. `tiles_from_template(...)` is exported for constructing template-based tile definitions.

### Operating contract

| Concern           | Required behavior                                                                |
| ----------------- | -------------------------------------------------------------------------------- |
| Execution surface | Pinned `unitlab==3.0.0` application environment on Python 3.10+.                 |
| Identity          | Least-privilege API key supplied through approved configuration.                 |
| Target resolution | Stable resource IDs and an explicitly bounded target set.                        |
| Success evidence  | Typed return fields, server-side state, and downstream acceptance of the result. |

### Failure and recovery boundary

| Condition                                       | Response                                                                                                     |
| ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| Authentication or authorization fails           | Stop, correct the service identity or access model, rotate exposed credentials, and rerun a read-only check. |
| Validation or entitlement rejects the operation | Correct the input or entitlement; do not retry an unchanged request.                                         |
| A request times out                             | Inspect remote state before repeating a mutation because the server may have accepted it.                    |
| Asynchronous processing exceeds its deadline    | Preserve the Batch Queue or release ID, continue bounded monitoring, and inspect item-level failures.        |
| Only part of a batch succeeds                   | Keep successful identifiers, isolate failed rows, and retry only the corrected subset.                       |

{% hint style="warning" %}
Pin and test the production SDK version. Use stable IDs, keep secrets out of logs and command history, and record the correlation ID, target IDs, counts, final state, and redacted error details for material state changes.
{% endhint %}
