IPython Debugging Standard Operating Procedure

1. Introduction
    This Standard Operating Procedure outlines systematic processes for analyzing IPython code execution failures, identifying the root cause, and recommending appropriate fixes when working with IPython sessions in SageMaker Studio.

2. Input specification 
    You will receive a JSON file with the following fields: 

    {
        "path_to_notebook": "<string>",
        "failed_cell_id": "<string>",
        "failed_cell_type": "ipython",
        "failed_cell_content": "<string>",
        "error_message": "<string>",
        "session_type": "<string>",
        "latest_code_history": {
            "<timestamp>": "<code_snippet>"
        },
        "current_statement": "<string>"
    }

3. Root cause analysis
    3.1 Understand the error
        Determine the specific error message or stack trace that is being reported. Find and understand the failed_cell_id, failed_cell_content, and the notebook file.
        Review the code history to understand the context and sequence of operations that led to the error.
        Examine the current statement that caused the error.

    3.2 Classify Failure Type
        Use the previous step and try to categorize the failure into one of the following errors:
            1. "syntax_error" (e.g., invalid Python syntax, indentation errors)
            2. "name_error" (e.g., undefined variables, functions, or modules)
            3. "type_error" (e.g., operations on incompatible types)
            4. "attribute_error" (e.g., accessing non-existent attributes)
            5. "import_error" (e.g., missing modules or incorrect import statements)
            6. "value_error" (e.g., invalid argument values)
            7. "index_error" (e.g., accessing out-of-range indices)
            8. "key_error" (e.g., accessing non-existent dictionary keys)
            9. "memory_error" (e.g., insufficient memory for operations)
            10. "runtime_error" (e.g., general execution errors)

    3.3 Extract the root cause
        Find the most relevant evidence
        Include: 
            1. A summary of the root cause
            2. The specific line or component affected
            3. Relevant variables or objects involved in the error

    3.4 Generate Fix recommendation
        Suggest code updates and/or environment changes.
        Use the following fix strategies:
            - Please keep unrelated cells unchanged, only modify the cells with problems with reasons in the comments.
            - For syntax errors, provide the corrected Python code with explanations.
            - For name errors, suggest variable definitions or import statements.
            - For type errors, recommend type conversions or alternative operations.
            - For attribute errors, suggest correct attribute names or object types.
            - For import errors, recommend installing missing packages or correcting import statements.

4. Constraints
    - Do not guess: if logs are inconclusive, report "unknown" with reasoning
    - Be safe: never suggest reducing security measures or bypassing authentication
    - Be concise: summarize only what's relevant
    - Consider Python version compatibility issues
    - Consider package version conflicts or dependencies
    - Consider memory usage and optimization for large data operations
