Code Review
You are a senior Python developer.
Review this code for:
1. Security vulnerabilities
2. Performance bottlenecks
3. Readability issues
4. Missing error handling
5. Potential bugs
Rate each 1-5 (5=no issues).
Provide specific line references.
```python
{paste_code_here}
```
Generate Tests
Write pytest unit tests for this function.
Cover:
- Happy path (normal inputs)
- Edge cases (empty, None, boundaries)
- Error cases (invalid inputs, exceptions)
- At least 8 test functions
```python
{function_code}
```
Use descriptive test names:
def test_should_return_X_when_Y():
Write Documentation
Write a Google-style docstring for this
function. Include:
- Brief one-line summary
- Args: each parameter with type + description
- Returns: type + description
- Raises: exceptions with conditions
- Example: working usage example
```python
{function_code}
```
Debug This Error
I'm getting this error in Python:
ERROR:
{paste_error_traceback}
CODE (relevant section):
```python
{paste_code}
```
CONTEXT:
- Input: {what_data_you_passed}
- Expected: {what_should_happen}
- Actual: {what_happened}
Please:
1. Explain what caused the error
2. Provide the fixed code
3. Explain how to prevent it
Refactor Code
Refactor this code to:
- Follow PEP 8 style guidelines
- Use appropriate design patterns
- Improve readability
- Add type hints
- Remove code duplication
- Improve performance where possible
Explain each significant change.
Keep the same public API.
```python
{paste_code}
```
Explain Code
Explain this code to a junior developer
who knows Python basics but has never
seen this pattern.
For each section:
1. What it does (plain English)
2. Why it's written this way
3. What would break if removed
```python
{paste_code}
```
System Design
Design a system for: {description}
Requirements:
- Scale: {users} users, {requests} req/s
- Latency: {target} p99
- Availability: {uptime}%
Please cover:
1. Architecture diagram (ASCII)
2. Component choices + reasons
3. Database schema (if applicable)
4. API design (key endpoints)
5. Scaling strategy
6. Failure modes + mitigations
SQL / Data Queries
Natural language → SQL
I have these tables:
{paste_schema_or_describe_tables}
Write a SQL query that:
{describe_what_you_want}
Optimise for performance.
Explain the query logic.
Debug slow query
This query is slow (~5s on 1M rows).
Suggest indexes and query optimisations.
```sql
{paste_slow_query}
```
ML Code Helpers
Implement from scratch:
Implement {algorithm} in Python
without using sklearn.
Include: forward pass, loss, gradients.
Optimise training loop:
This training loop is slow.
Add: mixed precision, gradient
checkpointing, pin_memory.
```python
{paste_training_code}
```
Debug model not converging:
My model loss is {behaviour}.
Architecture: {describe_model}
Hyperparameters: {list_params}
What could cause this? How to fix?