{"record":{"id":"0da916f7f3ca55d6","repo":"HKUDS/Vibe-Trading","slug":"playbook-variable-key-r-is-len-text-chars-th","errorCode":null,"errorMessage":"playbook variable {key!r} is {len(text)} chars; the cap is {_MAX_VARIABLE_CHARS}","messagePattern":"playbook variable (.+?) is (.+?) chars; the cap is (.+?)","errorType":"validation","errorClass":"PlaybookError","httpStatus":null,"severity":"error","filePath":"agent/src/scheduled_research/playbooks.py","lineNumber":133,"sourceCode":"                is not declared by this playbook is an error rather than a\n                silent no-op. A blank value falls back to the declared default.\n\n        Returns:\n            The prompt text to hand to the scheduler.\n\n        Raises:\n            PlaybookError: If an undeclared variable is supplied or a value\n                exceeds the length cap.\n        \"\"\"\n        values = dict(self.variables)\n        for key, raw in (variables or {}).items():\n            if key not in values:\n                raise PlaybookError(\n                    f\"playbook {self.slug!r} has no variable {key!r}; declared: {sorted(values)}\"\n                )\n            text = str(raw).strip()\n            if len(text) > _MAX_VARIABLE_CHARS:\n                raise PlaybookError(\n                    f\"playbook variable {key!r} is {len(text)} chars; the cap is {_MAX_VARIABLE_CHARS}\"\n                )\n            if text:\n                values[key] = text\n        # Every placeholder in the body was checked against ``variables`` at\n        # load time, so this substitution cannot leave one behind.\n        return _PLACEHOLDER_RE.sub(lambda m: values[m.group(1)], self.body)\n\n    def to_job(\n        self,\n        *,\n        job_id: Optional[str] = None,\n        schedule: Optional[str] = None,\n        timezone: Any = _KEEP,\n        variables: Optional[Mapping[str, Any]] = None,\n        config: Optional[Mapping[str, Any]] = None,\n        next_run_at: Optional[int] = None,\n        now_ms: Optional[int] = None,","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/scheduled_research/playbooks.py#L115-L151","documentation":"Raised by Playbook.render (agent/src/scheduled_research/playbooks.py:133) as PlaybookError when a supplied variable value, after str() and strip(), exceeds the maximum allowed character count (_MAX_VARIABLE_CHARS). The cap limits how much injected text can land in the rendered prompt body.","triggerScenarios":"Passing a long topic description, pasted article text, or a multi-paragraph value to to_job/build_job_from_draft where the value's stripped length exceeds the cap constant defined in playbooks.py.","commonSituations":"Feeding user free-text input or LLM-generated content into a variable; progressive scope creep in prompt content; copying a full document where a summary was intended.","solutions":["Truncate before calling render: value[:cap] (read _MAX_VARIABLE_CHARS from the module)","Summarize long content upstream instead of truncating blindly","Validate input length at your API boundary with the same cap","Split oversized content across multiple runs or a different mechanism"],"exampleFix":"# before\njob = playbook.to_job(schedule=\"@daily\", variables={\"topic\": huge_text})\n\n# after\nfrom agent.src.scheduled_research.playbooks import _MAX_VARIABLE_CHARS\njob = playbook.to_job(schedule=\"@daily\", variables={\"topic\": huge_text[:_MAX_VARIABLE_CHARS]})","handlingStrategy":"validation","validationCode":"from agent.src.scheduled_research.playbooks import _MAX_VARIABLE_CHARS\n\ndef within_cap(text):\n    return len(str(text).strip()) <= _MAX_VARIABLE_CHARS","typeGuard":"from agent.src.scheduled_research.playbooks import _MAX_VARIABLE_CHARS\nfrom typing import Any\n\ndef capped(value: Any) -> str:\n    text = str(value).strip()\n    return text[:_MAX_VARIABLE_CHARS]","tryCatchPattern":"from agent.src.scheduled_research.playbooks import PlaybookError\n\ntry:\n    job = playbook.to_job(schedule=\"@daily\", variables=vars)\nexcept PlaybookError as exc:\n    if \"the cap is\" in str(exc):\n        vars = {k: str(v).strip()[:_MAX_VARIABLE_CHARS] for k, v in vars.items()}\n        job = playbook.to_job(schedule=\"@daily\", variables=vars)\n    else:\n        raise","preventionTips":["Enforce the same length cap on user input at your API boundary","Summarize long content before templating","Fail fast in CI by validating variable lengths before scheduling"],"tags":["playbook","input-length","validation","scheduled-research"],"backgroundTag":"input-exceeds-max-length","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}