# InvalidArgumentError: Row lengths must be non-negative. Got values: [-1, 3, 2]

- **ID:** `tensorflow/ragged-tensor-to-sparse-invalid-splits`
- **Domain:** tensorflow
- **Category:** data_error
- **Error Code:** `RTS`
- **Verification:** ai_generated
- **Fix Rate:** 75%

## Root Cause

Ragged tensor construction or conversion to sparse tensor encountered negative row lengths, typically due to corrupted data or incorrect indexing in nested tf.RaggedTensor.from_row_splits.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| tensorflow 2.10 | active | — | — |
| tensorflow 2.11 | active | — | — |
| tensorflow 2.12 | active | — | — |
| tensorflow 2.13 | active | — | — |

## Workarounds

1. **Validate and sanitize row splits before constructing RaggedTensor: row_splits = [0, 2, 5, 8]; row_splits = tf.maximum(row_splits, 0); row_splits = tf.cast(row_splits, tf.int64); rt = tf.RaggedTensor.from_row_splits(values, row_splits)** (80% success)
   ```
   Validate and sanitize row splits before constructing RaggedTensor: row_splits = [0, 2, 5, 8]; row_splits = tf.maximum(row_splits, 0); row_splits = tf.cast(row_splits, tf.int64); rt = tf.RaggedTensor.from_row_splits(values, row_splits)
   ```
2. **Use tf.RaggedTensor.from_value_rowids instead of from_row_splits if row lengths are derived from data: value_rowids = [0, 0, 1, 1, 1, 2, 2, 2]; rt = tf.RaggedTensor.from_value_rowids(values, value_rowids)** (75% success)
   ```
   Use tf.RaggedTensor.from_value_rowids instead of from_row_splits if row lengths are derived from data: value_rowids = [0, 0, 1, 1, 1, 2, 2, 2]; rt = tf.RaggedTensor.from_value_rowids(values, value_rowids)
   ```

## Dead Ends

- **Using tf.debugging.assert_all_values_non_negative on the entire tensor** — The error is in the splits structure, not the values; the assert would not catch the issue in row lengths. (85% fail)
- **Setting allow_negative=True on RaggedTensor constructor (non-existent flag)** — There is no such flag; negative row lengths are always invalid. (99% fail)
