Structured prompt formatting

From wenmin-wu/ds-skills · View interactive version

Structured prompt formatting is an AI agent skill from the GitHub repository wenmin-wu/ds-skills. Format multi-field tabular data into a structured natural language prompt with labeled sections for encoder or LLM classification

How to use this skill

Skill file

Structured Prompt Formatting

Overview

When input data has multiple fields (question, answer, explanation, metadata), concatenate them into a structured text prompt with labeled sections. This converts tabular rows into natural language that encoder models (BERT, DeBERTa) or LLMs (Gemma, Qwen) can process. Field labels act as implicit attention anchors, helping the model parse structure.

Quick Start

def format_prompt(row, fields, separator='\n'):
    """Format a row of data into a labeled text prompt.
    
    Args:
        row: dict-like row (DataFrame row, dict)
        fields: list of (label, column_name) tuples
        separator: delimiter between fields
    """
    parts = []
    for label, col in fields:
        value = row[col]
        if isinstance(value, bool):
            value = "Yes" if value else "No"
        parts.append(f"{label}: {value}")
    return separator.join(parts)

# Define field mapping
fields = [
    ("Question", "QuestionText"),
    ("Answer", "MC_Answer"),
    ("Correct", "is_correct"),
    ("Student Explanation", "StudentExplanation"),
]

df['text'] = df.apply(lambda row: format_prompt(row, fields), axis=1)
# Output: "Question: What is 2+2?\nAnswer: 5\nCorrect: No\nStudent Explanation: ..."

Key Decisions

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.