{"record":{"id":"a9a1112dc25144c9","repo":"sgl-project/sglang","slug":"given-arguments-mismatch-the-sgl-function-signatur","errorCode":null,"errorMessage":"Given arguments mismatch the SGL function signature","messagePattern":"Given arguments mismatch the SGL function signature","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"python/sglang/lang/ir.py","lineNumber":273,"sourceCode":"            stop_regex = []\n\n        assert isinstance(batch_kwargs, (list, tuple))\n        if len(batch_kwargs) == 0:\n            return []\n        if not isinstance(batch_kwargs[0], dict):\n            num_programs = len(batch_kwargs)\n            # change the list of argument values to dict of arg_name -> arg_value\n            batch_kwargs = [\n                {self.arg_names[i]: v for i, v in enumerate(arg_values)}\n                for arg_values in batch_kwargs\n                if isinstance(arg_values, (list, tuple))\n                and len(self.arg_names) - len(self.arg_defaults)\n                <= len(arg_values)\n                <= len(self.arg_names)\n            ]\n            # Ensure to raise an exception if the number of arguments mismatch\n            if len(batch_kwargs) != num_programs:\n                raise Exception(\"Given arguments mismatch the SGL function signature\")\n\n        default_sampling_para = SglSamplingParams(\n            max_new_tokens=max_new_tokens,\n            n=n,\n            stop=stop,\n            stop_token_ids=stop_token_ids,\n            stop_regex=stop_regex,\n            temperature=temperature,\n            top_p=top_p,\n            top_k=top_k,\n            min_p=min_p,\n            frequency_penalty=frequency_penalty,\n            presence_penalty=presence_penalty,\n            ignore_eos=ignore_eos,\n            return_logprob=return_logprob,\n            logprob_start_len=logprob_start_len,\n            top_logprobs_num=top_logprobs_num,\n            return_text_in_logprobs=return_text_in_logprobs,","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/lang/ir.py#L255-L291","documentation":"Raised by run_batch in sglang's frontend IR when the number of per-program argument dicts that pass signature validation does not equal num_programs. Each program in the batch must receive a compatible number of positional/keyword arguments for the SGL function (between len(arg_names)-len(arg_defaults) and len(arg_names)), so any single mismatched entry drops the count and triggers this exception.","triggerScenarios":"Calling sgl.run_batch (or run_batch on a traced SGL function) with a list of argument dicts where at least one dict has too few arguments (fewer than arg_names minus defaults) or more arguments than the function signature declares; batch size of valid kwargs then != num_programs.","commonSituations":"Passing heterogeneous batches where some entries miss required parameters, forgetting that parameters with defaults are optional but others are not, or refactoring an SGL function signature without updating all batch argument dicts.","solutions":["Check the SGL function signature (arg_names and arg_defaults) and make every dict in batch_kwargs supply all required arguments","Log len(batch_kwargs) vs num_programs and each dict's keys to find the offending entry","If some programs intentionally have fewer args, give the missing parameters defaults in the function definition"],"exampleFix":"# before\nprograms = [{\"x\": 1}, {\"x\": 2, \"y\": 3}]  # second dict has extra arg\nrun_batch(programs)\n\n# after\nprograms = [{\"x\": 1, \"y\": 0}, {\"x\": 2, \"y\": 3}]\nrun_batch(programs)","handlingStrategy":"validation","validationCode":"required = set(fn.arg_names) - set(fn.arg_defaults)\nfor i, kw in enumerate(batch_kwargs):\n    missing = required - set(kw)\n    extra = set(kw) - set(fn.arg_names)\n    assert not missing and not extra, (i, missing, extra)\nrun_batch(batch_kwargs)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep a single source of truth for the function signature and generate batch dicts from it","Add a preflight assert on len(batch_kwargs) == num_programs in tests"],"tags":["sglang","batch","arguments","signature-validation"],"backgroundTag":"function-argument-count-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}