{"record":{"id":"529a0d5f43e96b29","repo":"huggingface/transformers","slug":"text-and-ids-have-mismatched-lengths-len-texts-or","errorCode":null,"errorMessage":"Text and ids have mismatched lengths {len(texts_or_text_and_labels)} and {len(ids)}","messagePattern":"Text and ids have mismatched lengths (.+?) and (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/data/processors/utils.py","lineNumber":201,"sourceCode":"            if column_id is not None:\n                ids.append(line[column_id])\n            else:\n                guid = f\"{split_name}-{i}\" if split_name else str(i)\n                ids.append(guid)\n\n        return self.add_examples(\n            texts, labels, ids, overwrite_labels=overwrite_labels, overwrite_examples=overwrite_examples\n        )\n\n    def add_examples(\n        self, texts_or_text_and_labels, labels=None, ids=None, overwrite_labels=False, overwrite_examples=False\n    ):\n        if labels is not None and len(texts_or_text_and_labels) != len(labels):\n            raise ValueError(\n                f\"Text and labels have mismatched lengths {len(texts_or_text_and_labels)} and {len(labels)}\"\n            )\n        if ids is not None and len(texts_or_text_and_labels) != len(ids):\n            raise ValueError(f\"Text and ids have mismatched lengths {len(texts_or_text_and_labels)} and {len(ids)}\")\n        if ids is None:\n            ids = [None] * len(texts_or_text_and_labels)\n        if labels is None:\n            labels = [None] * len(texts_or_text_and_labels)\n        examples = []\n        added_labels = set()\n        for text_or_text_and_label, label, guid in zip(texts_or_text_and_labels, labels, ids):\n            if isinstance(text_or_text_and_label, (tuple, list)) and label is None:\n                text, label = text_or_text_and_label\n            else:\n                text = text_or_text_and_label\n            added_labels.add(label)\n            examples.append(InputExample(guid=guid, text_a=text, text_b=None, label=label))\n\n        # Update examples\n        if overwrite_examples:\n            self.examples = examples\n        else:","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/data/processors/utils.py#L183-L219","documentation":"SeqClassificationFeaturizer.add_examples requires that an explicit ids list (per-example GUIDs) match the length of texts_or_text_and_labels exactly. As with the labels check, this guards against zip() silently dropping unpaired examples, which would make dataset indices and GUIDs inconsistent.","triggerScenarios":"Calling add_examples(texts, labels=labels, ids=ids) where len(ids) != len(texts); reusing GUIDs generated for a previous, larger or smaller, batch of texts; passing ids=[...] while texts_or_text_and_labels is a list of (text, label) tuples.","commonSituations":"Precomputed ids from a prior preprocessing run applied to new data; slicing or subsampling texts without applying the same slice to ids; ids built with enumerate over a filtered list while texts came from the unfiltered list.","solutions":["Ensure ids is built from the same list comprehension/loop as texts (e.g. ids = [f'train-{i}' for i in range(len(texts)]).","Pass ids=None and let the featurizer auto-generate GUIDs if you do not need stable ids.","Add an assert len(texts) == len(ids) guard in your data-loading code before calling the API."],"exampleFix":"# before\nfeaturizer.add_examples(texts, labels=labels, ids=old_ids)  # stale ids\n\n# after\nids = [f\"train-{i}\" for i in range(len(texts))]\nfeaturizer.add_examples(texts, labels=labels, ids=ids)","handlingStrategy":"validation","validationCode":"if ids is not None:\n    assert len(texts) == len(ids), f\"texts={len(texts)} ids={len(ids)}\"\nfeaturizer.add_examples(texts, labels=labels, ids=ids)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Generate ids from the same enumeration that builds texts.","Pass ids=None unless stable GUIDs are required; the API will synthesize them.","Never reuse ids from a previous preprocessing run with new data."],"tags":["data-processing","validation","length-mismatch","ids"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}