Astronox Docs

Prompt Engineering Tips

Advanced techniques for crafting effective prompts.

Prompt Engineering Tips

Advanced techniques for crafting effective prompts.

Fundamentals

The Anatomy of a Good Prompt

Components:

[Context] + [Task] + [Format] + [Constraints]

Example:

"I'm working on a Python web scraper [CONTEXT]
that needs to extract product prices from e-commerce sites [TASK].
Generate a function using BeautifulSoup [FORMAT]
that handles pagination and rate limiting [CONSTRAINTS]."

Clarity Techniques

Use Explicit Instructions

Weak:

"Make this better"

Strong:

"Refactor this function to:
• Add type hints
• Improve variable names
• Add error handling for edge cases
• Include docstring"

Define Success Criteria

Tell AI what "good" looks like:

"Find large files that:
• Are bigger than 500MB
• Haven't been accessed in 90 days
• Are not in system folders
• Can safely be deleted or archived"

Specify Format

Output format matters:

"List files as a markdown table with columns:
Name | Size | Last Modified | Path"

Or:

"Return results as JSON with fields: filename, size_mb, date"

Context Enrichment

Provide Background

Minimal context:

"Fix this code"

Rich context:

"This Python script processes CSV files but fails on large datasets (>10k rows).
I'm seeing a MemoryError. I need to handle this without loading everything into memory.
Python 3.9, pandas available."

Include Examples

Show desired outcome:

"Rename files to this pattern:
Current: IMG_1234.jpg
Desired: 2025-12-20_vacation_001.jpg

Apply to all images in this folder"

Reference Previous Work

In same conversation:

"Use the same approach you used for organizing my Downloads,
but apply it to my Desktop instead"

Precision Techniques

Use Numbers

Vague:

"Find old files"

Precise:

"Find files older than 90 days"

Be Explicit About Scope

Ambiguous:

"Delete temp files"

Scoped:

"Delete .tmp files only from ~/Downloads,
not from system folders or applications"

Specify Units

Important for:

  • Time: "90 days" not "old"
  • Size: "500MB" not "large"
  • Quantity: "top 10" not "some"
  • Percentage: "80% full" not "almost full"

Structuring Complex Requests

Use Numbered Steps

Makes intent clear:

"Set up new project:
1. Create folder: ~/Work/project-name
2. Initialize git repository
3. Create these subfolders: src/, tests/, docs/
4. Generate .gitignore for Python
5. Create README.md with project title
6. Create requirements.txt with: flask, requests, pytest"

Use Bullet Points

For parallel tasks:

"Analyze this codebase:
• Count total lines of code
• Identify main programming languages used
• Find all TODO comments
• List external dependencies
• Check for common security issues"

Combine Both

"Optimize images workflow:
1. First, find all images in ~/Photos
   • Include: JPG, PNG, GIF
   • Exclude: already optimized (size < 100KB)
2. For each image:
   • Resize if width > 1920px
   • Compress to 80% quality
   • Preserve EXIF data
3. Save originals to ~/Photos/originals
4. Generate report of space saved"

Constraint Definition

Set Boundaries

Prevent unwanted actions:

"Organize files but:
• Don't delete anything
• Don't move system files
• Don't touch files modified in last 7 days
• Create new folders, don't delete existing ones"

Define Exclusions

What to avoid:

"Find large files, excluding:
• Anything in /System or /Library
• Active project folders
• Files currently open in apps
• macOS hidden files (.DS_Store, etc.)"

Specify Approvals Needed

"Plan the cleanup, but:
• Show me the list before deleting anything
• Ask for confirmation at each major step
• Don't proceed past step 3 without my approval"

Conditional Logic

If-Then Statements

"Check disk space:
• If >90% full → Find largest 20 files and suggest deletion
• If 70-90% full → Show summary and recommend cleanup
• If <70% full → Just report current usage"

Fallback Instructions

"Try to use pandas for CSV processing.
If pandas is not installed, use standard csv module instead.
If file is too large (>100MB), process in chunks."

Refinement Patterns

Progressive Enhancement

Start simple, add details:

You: "Find Python files"
AI: [Shows all .py files]

You: "Only ones modified this week"
AI: [Filtered list]

You: "That import 'requests' library"
AI: [Further filtered]

You: "Sort by size, largest first"
AI: [Final refined list]

Comparative Prompting

Use comparisons:

"Refactor this code similar to how modern React uses hooks,
but keep it compatible with our existing class-based components"

Role Assignment

Give AI a Perspective

Can improve relevance:

"As a security expert, review this code for vulnerabilities"
"As a performance consultant, analyze this script's efficiency"
"As a Python teacher, explain this code to a beginner"

Output Formatting

Request Specific Structure

Markdown:

"Format the results as:
# Summary
- Total files: X
- Total size: Y GB

## Breakdown by Type
| Type | Count | Size |
|------|-------|------|

Code:

"Generate Python code with:
• Type hints
• Docstrings (Google style)
• Error handling with try/except
• Comments for complex logic only"

Lists:

"List as:
Priority 1 (Critical):
  • Item
  • Item
Priority 2 (Important):
  • Item"

Error Handling in Prompts

Anticipate Issues

"Delete old log files, but if any are locked or in use:
• Skip them
• Note which files couldn't be deleted
• Continue with the rest"

Request Explanations

"If this operation fails, explain:
• What went wrong
• Why it failed
• How to fix it
• Alternative approaches"

Advanced Patterns

Chain of Thought

Ask AI to think through it:

"Before suggesting a solution:
1. Explain what's causing the problem
2. List 2-3 possible approaches
3. Compare pros/cons of each
4. Recommend the best option with reasoning
5. Then provide the implementation"

Meta-Prompting

Ask AI to improve your prompt:

"I want to organize my files but my request is unclear.
Here's what I said: [your original prompt]

How should I rephrase this to be more specific?"

Template Usage

Create reusable patterns:

"Using this template:
[Action] all [file type] in [location]
that [criteria]
and [output format]

Fill it in to organize my photos"

Common Prompt Patterns

Analysis Pattern

"Analyze [target]:
• Identify [aspects to examine]
• Look for [specific issues/patterns]
• Provide [type of output]
• Suggest [recommendations]"

Transformation Pattern

"Transform [source]:
• From [current format]
• To [desired format]
• Preserving [what to keep]
• Excluding [what to remove]"

Generation Pattern

"Generate [type of output]:
• Based on [input/requirements]
• Following [style/conventions]
• Including [must-have elements]
• Optimized for [use case]"

Comparison Pattern

"Compare [item A] and [item B]:
• Focus on [aspects]
• Highlight [differences/similarities]
• Conclude with [recommendation/summary]"

Debugging Prompts

When AI Doesn't Understand

Original:

"Fix the thing"

Debug:

"What additional information do you need to help me?"

Then provide clarification


When Results Are Off

Instead of frustration:

"That's not quite right. I meant [clarification].
Can you retry with this understanding?"

Test Understanding

Before execution:

"Before you do this, explain back to me what you think I'm asking for"

Optimization Tips

Reduce Token Usage

Verbose:

"I would like you to please help me find all of the files
that are located in my Documents folder, specifically those
that have the .pdf extension, and if you could also make sure
to only include the ones that are larger than 5 megabytes..."

Optimized:

"Find PDF files >5MB in ~/Documents"

Both work, but optimized is:

  • Faster
  • Cheaper (fewer tokens)
  • Clearer

Reuse Context

Don't repeat in same conversation:

❌ "Find PDFs in ~/Documents >5MB"
   [results]
   "Find JPGs in ~/Documents >5MB"  ← Repeating location

✅ "Find PDFs in ~/Documents >5MB"
   [results]
   "Now find JPGs there"  ← AI remembers location

Language and Tone

Imperative vs. Interrogative

Both work:

"Show me..." (imperative)
"Can you show me..." (interrogative)
"I need to see..." (declarative)

Choose what feels natural - AI handles all


Politeness

Not required, but doesn't hurt:

"Please find..." ← Works
"Find..." ← Also works, equally effective

Certainty Level

Express confidence:

Strong: "Delete these files" ← Confident
Weak: "Maybe delete these files?" ← Uncertain

AI matches your confidence level

Anti-Patterns (Avoid)

❌ Over-Prompting

Too much detail:

"Find files and I mean really search thoroughly through
every single subfolder without missing any and check
each file's properties including size and date and..."

AI can handle nuance - don't over-specify basic operations


❌ Ambiguous Pronouns

Unclear:

[Shows file list]
"Delete them"  ← Which ones? All? Some?

Clear:

"Delete the files you just listed"
"Delete items 1, 3, and 5 from that list"

❌ Conflicting Instructions

Contradictory:

"Find all files and delete only the old ones
but don't delete anything"

❌ Assumed Knowledge

Don't assume AI knows:

❌ "Find it" ← AI doesn't know what "it" is
✅ "Find the project folder I mentioned yesterday"
   (AI can check memory/history)

Practice Examples

Basic → Advanced

Level 1 (Beginner):

"Find large files"

Level 2 (Intermediate):

"Find files larger than 500MB in my home folder"

Level 3 (Advanced):

"Find files >500MB in ~ excluding:
• System folders
• Currently open files
• Anything modified in last 7 days
Sort by size descending, show top 20"

Level 4 (Expert):

"Analyze disk usage:
1. Find files >500MB (exclude system/active)
2. Categorize by type (video/images/archives/other)
3. For each category:
   • Total size
   • File count
   • Oldest file date
4. Suggest deletion candidates based on:
   • Size (>1GB files priority)
   • Age (>180 days)
   • Duplicate detection
5. Show me the suggestions before any deletion"

Quick Reference

Make prompts better by:

✅ Being specific (numbers, paths, criteria)
✅ Providing context (why, background, constraints)
✅ Using examples (show desired outcome)
✅ Structuring (numbered steps, bullets)
✅ Defining scope (what to include/exclude)
✅ Requesting previews (review before execute)
✅ Adding conditions (if-then logic)

❌ Being vague ("fix stuff")
❌ Using ambiguous pronouns ("delete them")
❌ Conflicting instructions
❌ Over-complicating simple requests
❌ Assuming AI knows unstated context


Next: Explore real-world Workflow Examples.