Skip to content

Reject empty old_string in edit tool#1709

Open
fallintoplace wants to merge 1 commit into
anthropics:mainfrom
fallintoplace:fix/reject-empty-edit-string
Open

Reject empty old_string in edit tool#1709
fallintoplace wants to merge 1 commit into
anthropics:mainfrom
fallintoplace:fix/reject-empty-edit-string

Conversation

@fallintoplace

Copy link
Copy Markdown

Problem

old_string is accepted as empty in the edit tool. Python str.replace treats an empty string as a match between every character, which can rewrite a file at every boundary when this tool is misused.

Fix

  • Add an early guard in beta_edit_tool: if old_string == "": raise ToolError("edit: old_string must not be empty").
  • Preserve existing uniqueness/missing-match validation for non-empty strings.

Scope

  • Only src/anthropic/lib/tools/agent_toolset.py change.
  • Existing behavior for valid (non-empty) replacements is unchanged.

Testing

Not run (behavioral validation change).

@fallintoplace fallintoplace requested a review from a team as a code owner June 25, 2026 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant