Skip to content

fix tool

Use fix to write xpd's fixes, as xpd check --fix does. It writes the safe fixes, then lints what is left and returns the same result as check. With unsafe, it first counts the unsafe fixes and asks the user to confirm them, because an unsafe fix may change what the code does.

fix(paths, unsafe=true)
lint paths and count the issues whose fix is "unsafe"
if the count is above zero
ask the user "Apply 2 unsafe fixes in bad.py? An unsafe fix may change what the code does."
if the client has to collect the answer first
return the question and write no file
if the user declines
write the safe fixes only and return what is left
write the safe and the unsafe fixes and return what is left

A client on a protocol older than 2026-07-28 gets the question during the call. A client on the 2026-07-28 protocol, or one that runs fix as a background task, gets the question as the result, and calls fix again with the answer.

fix(paths=null, unsafe=false, options=null)
  • May change files
  • May overwrite what is there
  • A second call with the same arguments changes nothing more
  • Stays inside the project

Tags: fix, lint.

The server gives the agent this description of the tool.

Write xpd's fixes into the files, then lint what is left.

Safe fixes keep what the code does. With unsafe, the user is asked to confirm first, because an unsafe fix may change behavior. Read the diff after unsafe fixes.

Type: list of string or null. Optional, default null.

Files or folders inside the project root. Default: the whole root.

Type: boolean. Optional, default false.

Also apply unsafe fixes, after the user confirms.

Type: object or null. Optional, default null.

Which rules run, and the project file that adds the project's own rules.

Field Type Required Default Description
options.rules list of string no Packages or public rule names.
options.severity "error", "warning", "info", "hint" or null no null Run only the rules of this severity and above.
options.config string or null no null A project file to read instead of the nearest sgconfig.yml, relative to the project root.

What xpd check found, after the fixes it wrote.

Field Type Required Default Description
fixed integer yes Number of fixes written to disk.
fixable integer yes Issues left that the fix tool fixes at the level asked for.
issues list of object yes
issues[].package string yes Module name of the rule's pack, such as pandas.
issues[].rule string yes Rule id, such as chained-assignment.
issues[].file string yes
issues[].line integer or null yes
issues[].column integer or null yes
issues[].severity "error", "warning", "info", "hint" yes
issues[].message string yes
issues[].fix "safe", "unsafe" or null yes How safe the rule's fix is, or null for no fix.

On samples/bad.py, whose two fixes are both unsafe, the user declined the question. The tool wrote no fix and returned the 5 issues that are left.

{"paths":["samples/bad.py"],"unsafe":true}
{"fixed":0,"fixable":0,"issues":"..."}

A path outside the project root fails before xpd runs. A client that cannot ask its user gets an error for an unsafe fix, and the server writes no file.