How to use the Code Refactoring Assistant.
Refactoring should preserve observable behavior unless a change is explicitly requested. Identify tests or examples that can detect an unintended difference.
Make the workflow fit your task.
Define the behavior that must remain unchanged and identify the duplication or complexity to address. Make a bounded structural change, then compare known cases, errors and side effects against the original.
- What you provide
- Code and requested structural change.
- What you get
- Refactored draft preserving intended behavior.
See the input and the result.
Illustrative input and output · a teaching example, not a live WebAct run
Example input
Refactor this Python function without changing its result or empty-name error:
def label(name, loud):
if loud:
if not name:
raise ValueError("name required")
return name.upper()
if not name:
raise ValueError("name required")
return name.lower()Completed example
def label(name, loud):
if not name:
raise ValueError("name required")
return name.upper() if loud else name.lower()
Checks: label("Ada", True) → "ADA"; label("Ada", False) → "ada". An empty string raises ValueError("name required") in both modes.Load this input into the prompt, then copy it to WebAct to try the task. Your result may differ from the illustration.
Decisions and troubleshooting.
Can refactoring intentionally change error behavior?
Only when that behavior change is part of the request. Otherwise preserve it or separate it into an explicit follow-up decision.
Why does extracting shared code alter one branch's result?
Check execution order, state and branch-specific conditions. Similar-looking code may perform its work under different assumptions.
Try it with your own source.
Replace the example with your material in the task prompt. Keep the requirements you need, then copy the task into WebAct.
Customize and copy the task ↑