{"record":{"id":"f3b32ee2ed58ed2e","repo":"GitbookIO/gitbook","slug":"there-is-no-previous-response-to-rate","errorCode":null,"errorMessage":"There is no previous response to rate.","messagePattern":"There is no previous response to rate\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/gitbook/src/components/AI/useSubmitAssistantFeedbackTool.ts","lineNumber":92,"sourceCode":"                        'ai_chat_tools_submit_assistant_feedback',\n                        (rating === 'good'\n                            ? tString(language, 'was_this_helpful_positive_label')\n                            : tString(language, 'was_this_helpful_negative_label')\n                        ).toLocaleLowerCase()\n                    ),\n                };\n            },\n            inputSchema: zodToJsonSchema(\n                SubmitAssistantFeedbackInputSchema as any\n            ) as AIToolDefinition['inputSchema'],\n            execute: async (input) => {\n                const { trackEvent, language, currentPage, displayContext, getResponseToRate } =\n                    ref.current;\n                const { rating } = SubmitAssistantFeedbackInputSchema.parse(input);\n\n                const { responseId, query } = getResponseToRate();\n                if (!responseId || !query) {\n                    throw new Error('There is no previous response to rate.');\n                }\n\n                // Attribute to the current page with an explicit context so the event still flushes\n                // on pathnames whose ambient insights context has no page (e.g. the embed's\n                // assistant tab), matching the submit-page-feedback tool.\n                const pageContext: InsightsEventPageContext = {\n                    pageId: currentPage?.pageId ?? null,\n                    displayContext,\n                };\n\n                trackEvent(\n                    {\n                        type: 'ask_rate_response',\n                        query,\n                        responseId,\n                        rating: rating === 'good' ? 1 : -1,\n                    },\n                    pageContext,","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/GitbookIO/gitbook/blob/db67585ee243d063c459a855988f21612cea9c95/packages/gitbook/src/components/AI/useSubmitAssistantFeedbackTool.ts#L74-L110","documentation":"Thrown by the submitAssistantFeedback AI tool (useSubmitAssistantFeedbackTool) when it executes with no rateable response available. The tool calls getResponseToRate() and requires both a responseId and a query; if the assistant has not produced (or finished producing) a response yet, the ids are missing and the tool throws before tracking feedback.","triggerScenarios":"The AI invokes the submit_assistant_feedback tool before any response_finish was recorded (no responseId); the tool executes after the conversation state was reset/cleared; getResponseToRate returns null query because no user question is tracked in state; the tool schema is called outside the chat flow that populates the rateable response.","commonSituations":"A model calling the feedback tool at the start of a session before answering; race where the tool call is processed while the response id hasn't been attached to chat state yet; stale prompt/tool definitions after a version change causing premature tool invocation.","solutions":["Prompt/ instruct the model (tool description) that the feedback tool must only be called after answering, ensuring a response exists.","In the tool's execute wrapper, degrade gracefully: return a user-facing message ('Nothing to rate yet') instead of throwing when responseId/query are absent.","Ensure the component invoking the tool receives the responseId from the chat stream (response_finish) and stores it before tools can run.","If it fires consistently, debug getResponseToRate's state wiring — the chat state may never record the last response."],"exampleFix":"// before\nconst { responseId, query } = getResponseToRate();\nif (!responseId || !query) {\n    throw new Error('There is no previous response to rate.');\n}\n\n// after\nconst { responseId, query } = getResponseToRate();\nif (!responseId || !query) {\n    return { success: false, reason: 'no-response-to-rate' };\n}","handlingStrategy":"validation","validationCode":"const { responseId, query } = getResponseToRate();\nif (!responseId || !query) {\n    // don't invoke the tool; tell the model there is nothing to rate yet\n    return;\n}","typeGuard":"const hasRateableResponse = (\n    r: { responseId: string | null; query: string | null } | undefined\n): r is { responseId: string; query: string } =>\n    !!r && !!r.responseId && !!r.query;","tryCatchPattern":"try {\n    await submitAssistantFeedbackTool.execute(input);\n} catch (error) {\n    if (error instanceof Error && error.message === 'There is no previous response to rate.') {\n        return { success: false, reason: 'no-response' };\n    }\n    throw error;\n}","preventionTips":["Tool descriptions should state the tool must run after a completed answer.","Persist the last responseId in chat state as soon as response_finish arrives.","Treat 'nothing to rate' as a normal outcome, not an exception, in tool wrappers."],"tags":["ai","tools","feedback","state","gitbook"],"backgroundTag":"invalid-tool-arguments","analyzedSha":"db67585ee243d063c459a855988f21612cea9c95","analyzedAt":"2026-08-28T17:49:47.831Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}