Auto Heal Hallucinated Code and Phantom Symbols
heal_hallucinated_codeDetect and repair hallucinated imports, identifiers, and method calls in AI-generated Python code by comparing candidate code against workspace AST symbol tables and applying AST corrections.
Instructions
Statically inspects candidate code against verified workspace AST symbol tables, detects phantom imports, misspelled identifiers, and hallucinated method calls, and rewrites the AST to the correct valid local identifier, distinguishing from 'verify_security_guard' and 'audit_code_quality' by actively applying AST node corrections rather than merely reporting violations or secret leaks.
Parameters:
code(str, required): The candidate Python source code string containing potential AI hallucinations or phantom methods.workspace_dir(str, optional, default='.'): Target repository root directory containing ground-truth AST symbol definitions.
Behavior:
Mutability: Non-destructive in-memory analysis and AST transformation; does not alter disk files.
Idempotency: Returns identical corrected code and diffs for identical candidate code input.
Performance & Latency: Completes AST inspection and healing in <100ms; consumes <35MB RAM.
Privacy: 100% offline local AST parsing; zero external network transmission.
Auth & Limits: Zero external credentials or API keys required; zero rate limits.
Error Handling: Emits clean syntax error diagnostic if candidate code fails initial AST parsing.
Usage Guidelines:
When to use: Use when repairing AI-generated code that contains hallucinated method names, phantom imports, or misspelled identifiers against real workspace AST symbol tables.
When NOT to use: Do not use for general codebase static linting (use 'audit_code_quality' instead); do not use when merely checking if code is safe to execute without applying AST repairs (use 'verify_security_guard' instead).
Returns: Formatted Markdown report containing total repaired symbols, confidence percentages, unified AST diff, and healed code block.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Candidate Python code to inspect and repair. | |
| workspace_dir | No | Target repository root directory (default: current directory). | . |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |