Be specific about context:
Request step-by-step explanations:
Write a Python function to process CSV data. Explain each step of your implementation.
Start with requirements, not implementation:
I need a function that takes a list of user records and returns only active users sorted by registration date. Use JavaScript.
Include examples for clarity:
Input: [{"name": "Alice", "active": true, "registered": "2023-01-15"},
{"name": "Bob", "active": false, "registered": "2022-11-03"}]
Expected output: [{"name": "Alice", "active": true, "registered": "2023-01-15"}]
Ask:
Write a Python function that calculates the Fibonacci sequence up to n terms.
Result:
def fibonacci(n):
"""Generate Fibonacci sequence up to n terms."""
sequence = []
if n <= 0:
return sequence
if n >= 1:
sequence.append(0)
if n >= 2:
sequence.append(1)
for i in range(2, n):
sequence.append(sequence[i-1] + sequence[i-2])
return sequence
# Example usage
print(fibonacci(10)) # [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
Start simple and build complexity:
Can you modify the function to be more memory efficient using a generator?
Request specific improvements:
Add error handling for negative inputs and type validation.
Ask for optimization:
Can you optimize this code for performance? The current implementation is too slow.
Improved version:
def fibonacci_generator(n):
"""Generate Fibonacci sequence up to n terms using a generator."""
if not isinstance(n, int):
raise TypeError("Input must be an integer")
if n < 0:
raise ValueError("Input must be a non-negative integer")
if n > 0:
yield 0
if n > 1:
yield 1
a, b = 0, 1
for _ in range(2, n):
a, b = b, a + b
yield b
# Example usage
print(list(fibonacci_generator(10))) # [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
Share the complete error message:
I'm getting this error: "TypeError: cannot unpack non-iterable int object"
Here's my code: [paste code here]
Provide execution context:
This function works with small inputs but crashes with larger datasets.
Ask for explanations, not just fixes:
Can you explain why this error is occurring and how to fix it?
Error:
RecursionError: maximum recursion depth exceeded
Code:
def factorial(n):
return n * factorial(n - 1)
LLM-assisted fix:
def factorial(n):
if n == 0 or n == 1:
return 1
return n * factorial(n - 1)
Request comprehensive test cases:
Generate unit tests for this function covering edge cases and normal operation.
Ask for specific testing frameworks:
Write pytest test cases for this user authentication function.
Generate test data:
Create sample test data for validating this e-commerce checkout process.
import pytest
from fibonacci import fibonacci_generator
def test_fibonacci_zero_terms():
assert list(fibonacci_generator(0)) == []
def test_fibonacci_one_term():
assert list(fibonacci_generator(1)) == [0]
def test_fibonacci_two_terms():
assert list(fibonacci_generator(2)) == [0, 1]
def test_fibonacci_ten_terms():
assert list(fibonacci_generator(10)) == [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
def test_fibonacci_negative_input():
with pytest.raises(ValueError):
list(fibonacci_generator(-1))
def test_fibonacci_type_error():
with pytest.raises(TypeError):
list(fibonacci_generator("10"))
Create function docstrings:
Write detailed docstrings for this Python class following NumPy style.
Generate README files:
Create a README.md for my project that [describe project].
Create API documentation:
Generate OpenAPI documentation for this REST endpoint.
def process_transaction(transaction_id, amount, currency="USD", description=None):
"""
Process a financial transaction and record it in the database.
Parameters
----------
transaction_id : str
Unique identifier for the transaction
amount : float
The amount to be processed, must be positive for credits,
negative for debits
currency : str, optional
Three-letter ISO currency code, by default "USD"
description : str, optional
Additional information about the transaction
Returns
-------
dict
Transaction receipt with status and confirmation number
Raises
------
ValueError
If amount is zero or currency is invalid
TransactionError
If the transaction processing fails
Examples
--------
>>> process_transaction("T123", 99.99, description="Annual subscription")
{'status': 'success', 'confirmation': 'C987654321', 'timestamp': '2023-06-01T14:30:00Z'}
"""
Hallucinated APIs and functions:
Outdated knowledge:
Security vulnerabilities:
Define requirements with the LLM:
I need to add a user profile export feature that generates a PDF summary.
What components would I need to build?
Generate component architecture:
Create a sequence diagram for the user profile export flow.
Implement components incrementally
Test and refine
Ask for conceptual overview:
Explain how React hooks work and when to use them.
Request example implementation:
Show me how to implement a custom useState hook for form validation.
Ask for best practices:
What are common mistakes when using React hooks?
Build incrementally with guidance
Contact: