Skip to content

Instantly share code, notes, and snippets.

@heiko-braun
Created February 20, 2025 08:12
Show Gist options
  • Select an option

  • Save heiko-braun/11d786c9712de612ccca7d32c9eb692b to your computer and use it in GitHub Desktop.

Select an option

Save heiko-braun/11d786c9712de612ccca7d32c9eb692b to your computer and use it in GitHub Desktop.

Prompt Structure Template

1. Using XML-style Tags for Clear Boundaries

<instructions>
Your task is to analyze customer data and generate insights.
Follow these rules:
- Maintain data types as specified
- Handle missing fields gracefully
- Round numerical values to 2 decimal places
</instructions>

<input_schema>
{
  "customer": {
    "id": "string",
    "profile": {
      "name": "string",
      "segment": "string",
      "joinDate": "ISO8601 date"
    },
    "transactions": [
      {
        "id": "string",
        "amount": "number",
        "date": "ISO8601 date",
        "category": "string"
      }
    ]
  }
}
</input_schema>

<output_schema>
{
  "analysis": {
    "customerValue": "number",
    "segmentInsights": "string",
    "recommendations": ["string"]
  },
  "metadata": {
    "processedAt": "ISO8601 date",
    "dataQuality": "number (0-1)"
  }
}
</output_schema>

<example_input>
{
  "customer": {
    "id": "C123",
    "profile": {
      "name": "John Doe",
      "segment": "Premium",
      "joinDate": "2023-01-15"
    },
    "transactions": [
      {
        "id": "T789",
        "amount": 299.99,
        "date": "2023-03-20",
        "category": "Electronics"
      }
    ]
  }
}
</example_input>

<example_output>
{
  "analysis": {
    "customerValue": 299.99,
    "segmentInsights": "Premium customer with focus on electronics",
    "recommendations": [
      "Offer extended warranty",
      "Suggest complementary accessories"
    ]
  },
  "metadata": {
    "processedAt": "2023-03-21T10:30:00Z",
    "dataQuality": 1.0
  }
}
</example_output>

2. Using Markdown-Style Sections

# Task Description
Analyze customer data to generate insights and recommendations.

# Processing Rules
1. Maintain data types as specified
2. Handle missing fields gracefully
3. Round numerical values to 2 decimal places

# Input Schema
```json
{
  "customer": {
    "id": "string",
    // schema continues...
  }
}

Output Schema

{
  "analysis": {
    // schema continues...
  }
}

Examples

Input Example

{
  // example input...
}

Output Example

{
  // example output...
}

## 3. Using Delimiter-Based Sections

===== INSTRUCTIONS ===== Analyze customer data and generate insights.

===== RULES =====

  1. Maintain data types as specified
  2. Handle missing fields gracefully
  3. Round numerical values to 2 decimal places

===== INPUT SCHEMA ===== { // schema definition... }

===== OUTPUT SCHEMA ===== { // schema definition... }

===== EXAMPLES ===== Input: { // example input... }

Expected Output: { // example output... }


## Best Practices for Section Demarcation

1. Consistent Delimiters
- Use the same style throughout the prompt
- Make delimiters visually distinct
- Ensure delimiters don't appear in the content

2. Hierarchical Structure
- Move from general to specific
- Group related information
- Use clear section titles

3. Visual Spacing
- Use blank lines between sections
- Maintain consistent indentation
- Align related elements

4. Clear Transitions
- Signal transitions between sections
- Use numbered steps for sequences
- Include section descriptions

5. Validation Markers

<validation_rules>

  • Required fields: ["id", "name"]
  • Data types: { "id": "string", "amount": "number" }
  • Constraints: { "amount": "> 0", "date": "ISO8601" } </validation_rules>

6. Error Handling Specifications

<error_handling>

  • Missing fields: Return null for optional fields
  • Invalid types: Report in metadata.errors array
  • Constraint violations: Include in validation_results </error_handling>

7. Processing Steps

<processing_steps>

  1. Validate input structure
  2. Transform data according to schema
  3. Apply business rules
  4. Generate insights
  5. Format output </processing_steps>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment