{"record":{"id":"c174994ed53db774","repo":"redis/redis-py","slug":"specific-argument-can-be-only-keys-or-strings","errorCode":null,"errorMessage":"specific_argument can be only keys or strings","messagePattern":"specific_argument can be only keys or strings","errorType":"validation","errorClass":"DataError","httpStatus":null,"severity":"error","filePath":"redis/commands/core.py","lineNumber":4622,"sourceCode":"        ``value1`` and ``value2`` Can be two strings or two keys\n        ``specific_argument`` Specifying if the arguments to the algorithm\n        will be keys or strings. strings is the default.\n        ``len`` Returns just the len of the match.\n        ``idx`` Returns the match positions in each string.\n        ``minmatchlen`` Restrict the list of matches to the ones of a given\n        minimal length. Can be provided only when ``idx`` set to True.\n        ``withmatchlen`` Returns the matches with the len of the match.\n        Can be provided only when ``idx`` set to True.\n\n        For more information, see https://redis.io/commands/stralgo\n        \"\"\"\n        # check validity\n        supported_algo = [\"LCS\"]\n        if algo not in supported_algo:\n            supported_algos_str = \", \".join(supported_algo)\n            raise DataError(f\"The supported algorithms are: {supported_algos_str}\")\n        if specific_argument not in [\"keys\", \"strings\"]:\n            raise DataError(\"specific_argument can be only keys or strings\")\n        if len and idx:\n            raise DataError(\"len and idx cannot be provided together.\")\n\n        pieces: list[EncodableT] = [algo, specific_argument.upper(), value1, value2]\n        if len:\n            pieces.append(b\"LEN\")\n        if idx:\n            pieces.append(b\"IDX\")\n        try:\n            int(minmatchlen)\n            pieces.extend([b\"MINMATCHLEN\", minmatchlen])\n        except TypeError:\n            pass\n        if withmatchlen:\n            pieces.append(b\"WITHMATCHLEN\")\n\n        return self.execute_command(\n            \"STRALGO\",","sourceCodeStart":4604,"sourceCodeEnd":4640,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/commands/core.py#L4604-L4640","documentation":"Raised by stralgo() when specific_argument is neither 'keys' nor 'strings'. This parameter tells Redis whether value1/value2 should be treated as key names to look up or as literal string values; any other value is meaningless to the command. It is a DataError.","triggerScenarios":"Calling client.stralgo('LCS', v1, v2, specific_argument='values'), specific_argument='key', or omitting the default and passing an arbitrary string.","commonSituations":"Typing 'value' instead of 'strings', or 'key' instead of 'keys'. Confusing whether to pass key names or raw strings.","solutions":["Set specific_argument='strings' to compare literal string values, or specific_argument='keys' to compare values stored at those keys.","Double-check spelling: it must be exactly 'keys' or 'strings' (plural)."],"exampleFix":"# before\nclient.stralgo('LCS', 'k1', 'k2', specific_argument='key')\n\n# after\nclient.stralgo('LCS', 'k1', 'k2', specific_argument='keys')","handlingStrategy":"validation","validationCode":"if specific_argument not in ('keys', 'strings'):\n    raise ValueError(\"specific_argument must be 'keys' or 'strings'\")\nclient.stralgo('LCS', v1, v2, specific_argument=specific_argument)","typeGuard":"from typing import Literal\n\ndef is_valid_specific_arg(s: str) -> bool:\n    return s in ('keys', 'strings')\n\n# usage\nspecific_argument: Literal['keys', 'strings'] = 'strings'","tryCatchPattern":"from redis.exceptions import DataError\ntry:\n    client.stralgo('LCS', v1, v2, specific_argument=specific_argument)\nexcept DataError as e:\n    if 'specific_argument' in str(e):\n        specific_argument = 'strings'\n        client.stralgo('LCS', v1, v2, specific_argument=specific_argument)","preventionTips":["Use a Literal['keys','strings'] type annotation on the variable holding specific_argument.","Validate user/config input against the two allowed values before forwarding."],"tags":["stralgo","lcs","validation","argument-value"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}