# ValueError: RaggedTensor from tf.ragged.constant has inconsistent row lengths: row 2 has length 5 but expected length 3 based on first row

- **ID:** `tensorflow/ragged-tensor-batch`
- **Domain:** tensorflow
- **Category:** type_error
- **Error Code:** `RTI`
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

When creating a RaggedTensor from nested lists, the specified row lengths do not match; for a uniform-ragged conversion, all rows must have the same number of values per partition.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| tensorflow>=2.8.0 | active | — | — |
| python>=3.7 | active | — | — |

## Workarounds

1. **Ensure that the input nested list has consistent row lengths for the first dimension. For example, if you have variable-length sequences, use `tf.ragged.constant` with `ragged_rank=1` and provide a list of lists where each inner list can have different lengths: `tf.ragged.constant([[1,2], [3,4,5]])`. The error occurs only if you try to create a uniform tensor from ragged data.** (90% success)
   ```
   Ensure that the input nested list has consistent row lengths for the first dimension. For example, if you have variable-length sequences, use `tf.ragged.constant` with `ragged_rank=1` and provide a list of lists where each inner list can have different lengths: `tf.ragged.constant([[1,2], [3,4,5]])`. The error occurs only if you try to create a uniform tensor from ragged data.
   ```
2. **Use `tf.RaggedTensor.from_row_lengths` to explicitly specify row lengths: `tf.RaggedTensor.from_row_lengths(values=[1,2,3,4,5], row_lengths=[2,3])`. This gives full control over the ragged structure.** (85% success)
   ```
   Use `tf.RaggedTensor.from_row_lengths` to explicitly specify row lengths: `tf.RaggedTensor.from_row_lengths(values=[1,2,3,4,5], row_lengths=[2,3])`. This gives full control over the ragged structure.
   ```

## Dead Ends

- **Using tf.ragged.constant with ragged_rank=1 to force raggedness but ignoring the structure.** — If the data is not truly ragged (i.e., variable-length), setting ragged_rank incorrectly can cause silent data corruption or downstream shape errors. (70% fail)
- **Padding all rows to the same length with -1 values and then using tf.ragged.boolean_mask.** — Padding changes the data semantics and the mask may not correctly reconstruct the original ragged structure; also inefficient. (60% fail)
