Skip to content
Back to skills

Structured Prompt Formatting

ASecurity

Format multi-field tabular data into a structured natural language prompt with labeled sections for encoder or LLM classification

  • 61 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 12, 2026
ai-agentspython

Security analysis

A100/100

Scanned September 12, 2026

npx -y skills add wenmin-wu/ds-skills --skill structured-prompt-formatting --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Structured Prompt Formatting?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Structured Prompt Formatting
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/wenmin-wu-structured-prompt-formatting/badge)](https://www.skillsdirectory.com/skills/wenmin-wu-structured-prompt-formatting)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: nlp-structured-prompt-formatting
description: Format multi-field tabular data into a structured natural language prompt with labeled sections for encoder or LLM classification
domain: nlp
---

# 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

```python
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

- **Labeled fields**: "Question:", "Answer:" etc. help the model parse structure vs raw concatenation
- **Newline separator**: mimics natural document structure; use [SEP] for BERT-style models
- **Boolean formatting**: convert True/False to Yes/No for more natural language
- **Field ordering**: put most important fields first — attention patterns favor early tokens

## References

- Source: [gemma2-9b-it-cv-0-945](https://www.kaggle.com/code/cdeotte/gemma2-9b-it-cv-0-945)
- Competition: MAP - Charting Student Math Misunderstandings

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…