{"record":{"id":"8f55bde3022a81c0","repo":"rohitg00/ai-engineering-from-scratch","slug":"model-script-exhausted","errorCode":null,"errorMessage":"model script exhausted","messagePattern":"model script exhausted","errorType":"exception","errorClass":"ToolLoopError","httpStatus":null,"severity":"error","filePath":"certifications/claude/lessons/10-tool-use-and-agentic-loops/code/main.py","lineNumber":229,"sourceCode":"        try:\n            tool.validate(arguments)\n            if tool.mutates and not approve(tool, arguments):\n                return {**result, \"content\": \"Approval denied\", \"is_error\": True}\n            value = tool.handler(arguments)\n            return {**result, \"content\": json.dumps(value, sort_keys=True)}\n        except Exception as exc:\n            return {**result, \"content\": f\"{type(exc).__name__}: {exc}\", \"is_error\": True}\n\n\nclass ScriptedModel:\n    def __init__(self, responses: list[dict[str, Any]]) -> None:\n        self.responses = copy.deepcopy(responses)\n        self.requests: list[list[dict[str, Any]]] = []\n\n    def create(self, messages: list[dict[str, Any]]) -> dict[str, Any]:\n        self.requests.append(copy.deepcopy(messages))\n        if not self.responses:\n            raise ToolLoopError(\"model script exhausted\")\n        return self.responses.pop(0)\n\n\nclass ToolLoop:\n    def __init__(\n        self,\n        model: ScriptedModel,\n        registry: ToolRegistry,\n        approve: Callable[[Tool, dict[str, Any]], bool] = lambda _tool, _args: False,\n        max_turns: int = 8,\n    ) -> None:\n        self.model = model\n        self.registry = registry\n        self.approve = approve\n        self.max_turns = max_turns\n\n    def run(self, request: str) -> tuple[str, list[dict[str, Any]]]:\n        messages: list[dict[str, Any]] = [{\"role\": \"user\", \"content\": request}]","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/certifications/claude/lessons/10-tool-use-and-agentic-loops/code/main.py#L211-L247","documentation":"Error \"model script exhausted\" thrown in rohitg00/ai-engineering-from-scratch.","triggerScenarios":"Thrown at certifications/claude/lessons/10-tool-use-and-agentic-loops/code/main.py:229 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","schemaVersion":2},"datasetVersion":"2026-08-26T07:17:17.940Z"}