Open kgilpin opened 1 month ago
Implement Retry Mechanism for Sonnet Error "Output blocked by content filtering policy"
When using the AnthropicCompletionService, an error "Output blocked by content filtering policy" is sometimes encountered, causing failures in running commands without retries.
The error "Output blocked by content filtering policy" indicates that the content has been flagged by a filtering policy, halting the operation. To make the system more robust, a retry mechanism should be implemented when this specific error occurs. The retry mechanism should attempt to re-execute the operation up to a certain limit before finally failing, ensuring resilience against transient filtering errors.
packages/navie/src/services/anthropic-completion-service.ts:
Introduce a retry mechanism when this specific error is encountered inside the complete
function.
complete
method to catch the specific "Output blocked by content filtering policy" error.packages/navie/src/lib/errors.ts:
Define a new custom error class for filtering policy errors to encapsulate the specific error condition.
packages/navie/src/commands/explain-command.ts:
Ensure that the execute
function in ExplainCommand
is compatible with the retry mechanism introduced in the AnthropicCompletionService
.
packages/navie/src/navie.ts:
Update the logic for the execute
function to handle retries properly when the AnthropicCompletionService
throws the specific custom error.
Here are the detailed changes:
packages/navie/src/services/anthropic-completion-service.ts:
complete
method.packages/navie/src/lib/errors.ts:
FilteringPolicyError
which will be used to identify and handle the filtering policy-related errors.packages/navie/src/commands/explain-command.ts:
execute
function to retry invoking the AnthropicCompletionService.complete
method when the new FilteringPolicyError
is raised.packages/navie/src/navie.ts:
AnthropicCompletionService
by updating the execute
function to properly capture and respond to retried operations.By implementing these changes, the codebase will effectively handle the "Output blocked by content filtering policy" errors by retrying the intended operation, providing a more resilient and reliable system.
I can't consider this a high priority since these errors tend to recur when we re-run instances.
Error example:
https://support.anthropic.com/en/articles/9205721-why-am-i-receiving-an-output-blocked-by-content-filtering-policy-error
--
Plan changes for the navie package only. Do not propose changes to the client package.