> ## Documentation Index
> Fetch the complete documentation index at: https://developer.upsun.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Advanced prompting techniques for complex coding tasks

> This articles will give you an overview of prompting strategies that help coding assistants reason through difficult problems and produce higher-quality solutions.


export const PostMeta = ({data = {}}) => {
  const {author, date, image} = data;
  const authors = Array.isArray(author) ? author : author ? [author] : [];
  const resolveAuthor = slug => {
    const entry = AUTHOR_MAP[slug] || ({});
    const name = entry.name || slug;
    const github = entry.github || null;
    const linkedin = entry.linkedin || null;
    const url = github ? `https://github.com/${github}` : linkedin || null;
    const avatarUrl = github ? `https://github.com/${github}.png?size=64` : null;
    return {
      name,
      url,
      avatarUrl
    };
  };
  const formattedDate = date ? new Date(date).toLocaleDateString('en-US', {
    year: 'numeric',
    month: 'long',
    day: 'numeric'
  }) : null;
  if (!image && authors.length === 0 && !formattedDate) return null;
  const AUTHOR_MAP = {
    "aaron-collier": {
      "name": "Aaron Collier"
    },
    "aaron-dudenhofer": {
      "name": "Aaron Dudenhofer"
    },
    "aaron-porter": {
      "name": "Aaron Porter"
    },
    "adriaan-odendaal": {
      "name": "Adriaan Odendaal"
    },
    "ajmal": {
      "name": "Ajmal Siddiqui"
    },
    "akalipetis": {
      "name": "Antonis Kalipetis"
    },
    "alexander-varwijk": {
      "name": "Alexander Varwijk"
    },
    "alicia-bevilacqua": {
      "name": "Alicia Bevilacqua"
    },
    "amelie-deguerry": {
      "name": "Amelie Deguerry"
    },
    "anacidre": {
      "name": "Ana Cidre",
      "linkedin": "https://www.linkedin.com/in/ana-cidre"
    },
    "andoni": {
      "name": "Andoni Auzmendi"
    },
    "andrei-taranu": {
      "name": "Andrei (Alex) Taranu",
      "linkedin": "https://www.linkedin.com/in/andrei-alex-taranu/"
    },
    "andrew-baxter": {
      "name": "Andrew Baxter"
    },
    "andrew-melck": {
      "name": "Andrew Melck"
    },
    "antoine-crochet-damais": {
      "name": "Antoine Crochet Damais"
    },
    "augustin-delaporte": {
      "name": "Augustin Delaporte",
      "linkedin": "https://www.linkedin.com/in/augustindelaporte/"
    },
    "branislav-bujisic": {
      "name": "Branislav Bujisic"
    },
    "carl-smith": {
      "name": "Carl Smith"
    },
    "caroline-leroy": {
      "name": "Caroline Leroy"
    },
    "cati-mayer": {
      "name": "Cati Mayer"
    },
    "catplat": {
      "name": "C Trinkwon"
    },
    "ceelolulu": {
      "name": "Celeste van der Watt"
    },
    "chadwcarlson": {
      "name": "Chad Carlson",
      "github": "chadwcarlson",
      "linkedin": "https://www.linkedin.com/in/chadwcarlson"
    },
    "chris-ward": {
      "name": "Chris Ward"
    },
    "chris-yates": {
      "name": "Chris Yates"
    },
    "christian-sieber": {
      "name": "Christian Sieber"
    },
    "christopher-lockheardt": {
      "name": "Christopher Lockheardt"
    },
    "christopher-skene": {
      "name": "Christopher Skene"
    },
    "chuck-morgan": {
      "name": "Chuck Morgan"
    },
    "corey-dockendorf": {
      "name": "Corey Dockendorf"
    },
    "crell": {
      "name": "Crell"
    },
    "damz": {
      "name": "Damz"
    },
    "dan-morrison": {
      "name": "Dan Morrison"
    },
    "davidbonachera": {
      "name": "David Bonachera",
      "github": "davidbonachera",
      "linkedin": "https://www.linkedin.com/in/davidbonachera"
    },
    "dereliahmet1": {
      "name": "Ahmet Faruk Dereli"
    },
    "devicezero": {
      "name": "Jonas Kröger",
      "github": "devicezero",
      "linkedin": "https://www.linkedin.com/in/jonaskroeger/"
    },
    "doug-goldberg": {
      "name": "Doug Goldberg"
    },
    "duncan-naves": {
      "name": "Duncan Naves",
      "github": "duncannaves",
      "linkedin": "https://www.linkedin.com/in/duncan-naves-a94423aa"
    },
    "erika-bustamante": {
      "name": "Erika Bustamante"
    },
    "fabpot": {
      "name": "Fabien Potencier"
    },
    "flovntp": {
      "name": "Florent Huck",
      "github": "flovntp",
      "linkedin": "https://www.linkedin.com/in/florenthuck"
    },
    "fred-plais": {
      "name": "Fred Plais"
    },
    "gauthier-garnier": {
      "name": "Gauthier Garnier"
    },
    "gilzow": {
      "name": "Paul Gilzow"
    },
    "gmoigneu": {
      "name": "Guillaume Moigneu",
      "github": "gmoigneu",
      "linkedin": "https://www.linkedin.com/in/guillaumemoigneu/"
    },
    "gregqualls": {
      "name": "Greg Qualls"
    },
    "guguss": {
      "name": "Augustin Delaporte"
    },
    "haylee-millar": {
      "name": "Haylee Millar"
    },
    "ivana-kotur": {
      "name": "Ivana Kotur"
    },
    "jackrabbithanna": {
      "name": "Mark Hanna"
    },
    "jared-wright": {
      "name": "Jared Wright",
      "github": "jww-sh",
      "linkedin": "https://www.linkedin.com/in/jaredwaynewright"
    },
    "jessica-orozco": {
      "name": "Jessica Orozco"
    },
    "joey-stanford": {
      "name": "Joey Stanford"
    },
    "john-grubb": {
      "name": "John Grubb"
    },
    "jonas-kruger": {
      "name": "Jonas Kruger"
    },
    "kathryn-frazer": {
      "name": "Kathryn Frazer"
    },
    "kemiojo": {
      "name": "Kemi Elizabeth Ojogbede"
    },
    "kieronsambrook-smith": {
      "name": "Kieronsambrook Smith"
    },
    "laurent-arnoud": {
      "name": "Laurent Arnoud",
      "linkedin": "https://www.linkedin.com/in/laurent-arnoud-861b44121/"
    },
    "letoya-boyne": {
      "name": "Letoya Boyne"
    },
    "lolautruche": {
      "name": "Jérôme Vieilledent"
    },
    "lyly-lepinay": {
      "name": "Lyly Lepinay"
    },
    "manauwar-alam": {
      "name": "Manauwar Alam"
    },
    "marc-antoine-porri": {
      "name": "Marc Antoine Porri"
    },
    "maria-antinkaapo": {
      "name": "Maria Antinkaapo"
    },
    "maria-de-anton": {
      "name": "Maria De Anton"
    },
    "mark-dorison": {
      "name": "Mark Dorison"
    },
    "markus-hausammann": {
      "name": "Markus Hausammann"
    },
    "mary-thomas": {
      "name": "Mary Thomas"
    },
    "mathias-bolt-lesniak": {
      "name": "Mathias Bolt Lesniak"
    },
    "mathieu-strauch": {
      "name": "Mathieu Strauch"
    },
    "matthias-van-woensel": {
      "name": "Matthias Van Woensel",
      "linkedin": "https://www.linkedin.com/in/matthias-van-woensel-267a069"
    },
    "michael-sharp": {
      "name": "Michael Sharp"
    },
    "mupsi": {
      "name": "Marine Gandy"
    },
    "natalie-harper": {
      "name": "Natalie Harper"
    },
    "ngommenginger": {
      "name": "Nicolas Gommenginger",
      "linkedin": "https://www.linkedin.com/in/nicolas-gommenginger"
    },
    "nicholas-bennison": {
      "name": "Nicholas Bennison"
    },
    "nicholas-vahalik": {
      "name": "Nicholas Vahalik"
    },
    "nick-hardiman": {
      "name": "Nick Hardiman"
    },
    "nickanderegg": {
      "name": "Nickanderegg"
    },
    "nicolas-grekas": {
      "name": "Nicolas Grekas",
      "github": "nicolas-grekas",
      "linkedin": "https://www.linkedin.com/in/nicolasgrekas/"
    },
    "niti-malwade": {
      "name": "Niti Malwade"
    },
    "opensocialteam": {
      "name": "Opensocialteam"
    },
    "ori-pekelman": {
      "name": "Ori Pekelman"
    },
    "otavio-santana": {
      "name": "Otavio Santana"
    },
    "palwandi": {
      "name": "Pawan Alwandi",
      "github": "pawpy",
      "linkedin": "https://www.linkedin.com/in/pawanalwandi"
    },
    "patrick-boest": {
      "name": "Patrick Boest"
    },
    "patrick-dawkins": {
      "name": "Patrick Dawkins",
      "github": "pjcdawkins",
      "linkedin": "https://www.linkedin.com/in/patrickdawkins"
    },
    "patrick-klima": {
      "name": "Patrick Klima"
    },
    "pjcdawkins": {
      "name": "Pjcdawkins"
    },
    "prineet-kaurbhurji": {
      "name": "Prineet Kaurbhurji"
    },
    "quentin-sinig": {
      "name": "Quentin Sinig"
    },
    "ralt": {
      "name": "Florian Margaine",
      "github": "ralt",
      "linkedin": "https://www.linkedin.com/in/florian-margaine-43971136"
    },
    "ramanathanramakrishnamurthy": {
      "name": "Ramanathanramakrishnamurthy"
    },
    "remi-lejeune": {
      "name": "Rémi Lejeune"
    },
    "ribel": {
      "name": "Taras Kruts"
    },
    "robert-douglass": {
      "name": "Robert Douglass"
    },
    "rudy-weber": {
      "name": "Rudy Weber"
    },
    "ryan-hicks": {
      "name": "Ryan Hicks"
    },
    "sabri-helal": {
      "name": "Sabri Helal"
    },
    "savannah-bergeron": {
      "name": "Savannah Bergeron"
    },
    "shannon-vettes": {
      "name": "Shannon Vettes"
    },
    "shawn-ogasawara": {
      "name": "Shawn Ogasawara",
      "linkedin": "https://www.linkedin.com/in/shawn-ogasawara-83a9a0/"
    },
    "shawna-spoor": {
      "name": "Shawna Spoor"
    },
    "shedrack-akintayo": {
      "name": "Shedrack Akintayo"
    },
    "simon-ruggier": {
      "name": "Simon Ruggier"
    },
    "sophie-van-der-kindere": {
      "name": "Sophie Van Der Kindere"
    },
    "stefanos-thampis": {
      "name": "Stefanos Thampis"
    },
    "stephen-weinberg": {
      "name": "Stephen Weinberg"
    },
    "sukhman-virk": {
      "name": "Sukhman Virk"
    },
    "sumaira-nazir": {
      "name": "Sumaira Nazir"
    },
    "sumer": {
      "name": "Sümer Cip"
    },
    "syed-raza": {
      "name": "Syed Raza"
    },
    "tamara-bacchia": {
      "name": "Tamara Bacchia"
    },
    "tara-arnold": {
      "name": "Tara Arnold"
    },
    "theosakamg": {
      "name": "Mickael Gaillard",
      "github": "theosakamg"
    },
    "thomasdiluccio": {
      "name": "Thomas di Luccio"
    },
    "tim-anderson": {
      "name": "Tim Anderson"
    },
    "tom-helmer-hansen": {
      "name": "Tom Helmer Hansen"
    },
    "tylermills": {
      "name": "Tyler Mills"
    },
    "upsun": {
      "name": "Upsun"
    },
    "veronika-tolkachova": {
      "name": "Veronika Tolkachova",
      "linkedin": "https://www.linkedin.com/in/veronika-tolkachova-169167a2"
    },
    "vince-parker": {
      "name": "Vince Parker"
    },
    "vinnie-russo": {
      "name": "Vincenzo Russo"
    },
    "vrobert78": {
      "name": "Vincent Robert",
      "github": "vrobert78",
      "linkedin": "https://www.linkedin.com/in/vincent-robert-498a883"
    },
    "yuriy-babenko": {
      "name": "Yuriy Babenko"
    },
    "yuriy-gerasimov": {
      "name": "Yuriy Gerasimov"
    }
  };
  return <div className="post-meta">
      {(authors.length > 0 || formattedDate) && <div className="post-meta-info">
          {authors.length > 0 && <div className="post-meta-authors">
              {authors.map(slug => {
    const {name, url, avatarUrl} = resolveAuthor(slug);
    const inner = <>
                    {avatarUrl && <img src={avatarUrl} alt={name} className="post-meta-avatar" />}
                    <span className="post-meta-author-name">{name}</span>
                  </>;
    return url ? <a key={slug} href={url} target="_blank" rel="noopener noreferrer" className="post-meta-author">
                    {inner}
                  </a> : <span key={slug} className="post-meta-author">{inner}</span>;
  })}
            </div>}
          {authors.length > 0 && formattedDate && <span className="post-meta-separator" aria-hidden="true">·</span>}
          {formattedDate && <span className="post-meta-date">{formattedDate}</span>}
        </div>}
      {image && <img src={image} alt="" className="post-meta-image" aria-hidden="true" />}
    </div>;
};

<PostMeta data={{ author: ["gmoigneu"], date: "2025-05-08T14:00:00+00:00", image: "/images/posts/insights/advanced-prompting-techniques-for-coding/advanced-prompting-techniques-for-coding.webp" }} />

When you're tackling sophisticated development challenges or refactoring a large codebase, basic prompting approaches may fall short. Complex coding tasks such as implementing algorithms, designing architectures, or building systems with multiple integrated components require more advanced prompting techniques.

This articles will give you an overview of prompting strategies that help coding assistants reason through difficult problems and produce higher-quality solutions.

Most of the strategies are inspired from general white-paper about **Prompt Engineering** by *Lee Boonstra* and adapted to the Coding context.

## Chain of Thought prompting for algorithm development

Chain of Thought (CoT) prompting guides the coding assistant to break down complex reasoning into explicit steps. This is particularly valuable for algorithm development, where logic needs to be constructed. This is what we see appearing right now with reasoning models.

The technique works by instructing the assistant to solve the problem step by step, thinking through each part of the solution before writing any code:

```
Implement a TypeScript function to find the longest increasing subsequence in an array.

Think through this problem step by step:
1. First, define what we're looking for precisely
2. Consider the naive approach and its limitations
3. Develop a dynamic programming solution
4. Analyze the time and space complexity
5. Implement the optimized solution with appropriate comments

Then write the final solution with full TypeScript typing.
```

By explicitly requesting this step-by-step reasoning, you:

1. Force the assistant to consider the problem more thoroughly
2. Reduce the likelihood of errors in complex logic
3. Get insight into the assistant's reasoning, making it easier to spot mistakes
4. End up with better-documented code that explains its own approach

This technique is especially powerful for:

* Graph algorithms
* Dynamic programming problems
* Complex data transformations
* Optimization challenges
* Recursive algorithms

## Step-back prompting for architectural decisions

Step-back prompting is a technique where you ask the assistant to consider a higher-level view before diving into implementation details. This is invaluable for architectural decisions where the broader context matters significantly.

Here's how to apply this technique:

```
I need to implement a caching layer for our API service that handles user authentication.

Before writing any code, let's step back and consider:
1. What are the key requirements for a caching system in an authentication context?
2. What are the security implications we need to address?
3. What caching strategies would be appropriate for different types of authentication data?
4. How should we handle cache invalidation when credentials change?
5. What are the performance vs. consistency tradeoffs of different approaches?

After analyzing these aspects, recommend an architectural approach and then implement 
a TypeScript class that provides this caching functionality.
```

This approach is particularly useful when:

* Designing system architecture
* Making significant refactoring decisions
* Building reusable libraries or frameworks
* Implementing security-critical components
* Creating systems that must scale

## Using JSON schemas to define expected code structures

For complex code structures, providing a JSON schema can dramatically improve the quality of generated code. This works especially well for defining expected interfaces, API responses, or configuration objects:

```text theme={null}
Create a Python FastAPI application for a book management system.

The API should conform to this JSON schema for book objects:

{
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid",
      "description": "Unique identifier for the book"
    },
    "title": {
      "type": "string",
      "minLength": 1,
      "maxLength": 100
    },
    "author": {
      "type": "object",
      "properties": {
        "name": { "type": "string" },
        "biography": { "type": "string", "nullable": true }
      },
      "required": ["name"]
    },
    "publication_year": {
      "type": "integer",
      "minimum": 1000,
      "maximum": 2100
    },
    "genres": {
      "type": "array",
      "items": { "type": "string" },
      "minItems": 1
    },
    "available_copies": {
      "type": "integer",
      "minimum": 0
    }
  },
  "required": ["title", "author", "publication_year", "genres"]
}

Implement the complete API with endpoints for CRUD operations, proper validation, error handling, and data persistence using SQLAlchemy.
```

The schema provides clear constraints and expectations that help the coding assistant generate appropriate models, validation logic, and API endpoints that align with your data requirements.

<Note>
  If you are using a strongly typed language like TypeScript, adding the types to the prompt instead of a JSON schema is also possible.
</Note>

## Self-consistency through multiple solutions

For particularly complex problems, you can leverage the technique of generating multiple approaches and comparing them:

```
Implement an efficient Python function to detect cycles in a directed graph.

Generate three different approaches to solving this problem:
1. A solution using depth-first search
2. A solution using Tarjan's algorithm
3. A solution using topological sorting

For each approach, explain its:
- Time and space complexity
- Key advantages
- Potential limitations

Then, recommend which approach is best for a graph with approximately 10,000 nodes and 50,000 edges, and implement that solution with full type annotations and documentation.
```

This technique helps in several ways:

* It explores multiple valid solutions to complex problems
* It makes trade-offs explicit
* It provides you with alternatives if one approach doesn't work in your specific context
* It gives you deeper insight into the problem space

## Progressive disclosure of requirements

For very complex features, the progressive disclosure technique breaks down implementation into stages, allowing you to review and refine at each step:

```
We need to build a TypeScript library for handling complex form validation with 
nested fields, async validation rules, and dependency tracking between fields.

Let's approach this in stages:

Stage 1: First, design the core interfaces for the validation library without 
implementation. Focus on how developers would use this API and what types they 
would interact with.

[After reviewing the interfaces]

Stage 2: Implement the core validation engine that can process validation rules 
and track field validity state.

[After reviewing the core implementation]

Stage 3: Add support for field dependencies where validating one field requires 
values from other fields.

[After reviewing dependencies implementation]

Stage 4: Implement asynchronous validation support with proper loading states 
and error handling.
```

This approach:

* Makes complex implementations more manageable
* Gives you control points to provide feedback
* Ensures the foundation is solid before building advanced features
* Reduces the chance of fundamental design issues

## Combining structured and natural language requirements

For the most sophisticated coding tasks, combine structured requirements with natural language explanations:

```
Create a Python data pipeline for processing time series sensor data with anomaly detection.

Technical Requirements:
- Input: CSV files with timestamp, sensor_id, and multiple reading columns
- Output: Processed data in Parquet format with anomalies flagged
- Performance: Must process 50GB of data in under 30 minutes on standard hardware
- Deployment: Must work within an Apache Airflow environment

Functional Description:
The system monitors industrial equipment through multiple sensors. Each sensor 
generates readings every 5 seconds. We need to identify anomalies that might indicate equipment failure, specifically looking for:

1. Sudden spikes or drops in readings
2. Gradual drift beyond acceptable thresholds
3. Unusual patterns compared to historical data for similar time periods
4. Correlation anomalies between related sensors

Implementation Guidance:
- Use pandas for initial data loading but switch to Dask for processing at scale
- Implement statistical anomaly detection using robust algorithms suitable for time series
- Include proper logging and error handling
- Design the pipeline to be fault-tolerant and resumable
- Structure the code to make adding new anomaly detection algorithms easy in the future

Start by defining the core data structures and pipeline architecture, then implement the main processing components.
```

This comprehensive approach provides both specific technical constraints and broader context about the problem domain, helping the coding assistant understand not just what to build but why certain approaches might be more appropriate than others.

## Directed improvement through iterative prompting

For extremely sophisticated development tasks, use iterative prompting to refine solutions:

```
Let's build a TypeScript state management library similar to Redux but with improved TypeScript type safety and less boilerplate.

First iteration: Design the core types and basic store implementation with actions and reducers.

[Review the first output and then continue]

Great, now let's address these issues:
1. The type inference could be improved for action creators
2. We need better handling of async actions
3. Add support for middleware with proper typing

[Review the second iteration and continue]

Now let's enhance it with:
1. Add selector functions with memoization
2. Implement proper devtools integration
3. Create a React hook API for consuming the store

[Final review]

Finally, create a complete example using this library to manage a simple application state,
demonstrating all the features we've implemented.
```

This approach allows you to:

* Focus on one aspect of a complex system at a time
* Build incrementally with course corrections
* Address specific weaknesses in each iteration
* End up with a more polished final product

## Wrap-up

By employing these advanced prompting techniques for complex coding tasks, you can help coding assistants tackle problems that would be beyond their capabilities with simpler prompting approaches.

These methods essentially augment the reasoning capabilities of the underlying models, allowing them to work through difficulty by breaking it down into manageable pieces.

While we see a rise in the use of reasoning models, these will still need guidelines to output what you actually need.
