Stop 10 · NLP & Modern AITopics · 7/7

Prompt Engineering for Data Tasks

Part of the Data Science Roadmap

In short

LLMs can label reviews, pull fields from invoices and clean messy categories in minutes. Good prompts make the output consistent enough to drop straight into a DataFrame.

Writing clear, structured prompts to get an LLM to perform data tasks — labeling, summarizing, extracting structured information — often faster to set up than training a dedicated model.

The mascot hands a sample shirt to a tailor holding a measuring tape at a shop counter.

Think of it like this

Briefing the tailor

Tell a tailor 'make me a shirt' and you get a surprise. Hand over a sample shirt, exact measurements and 'no pocket, half sleeves' and you get what you wanted. Prompts are the same: clear instructions, a fixed format and an example.

Watch it happen

Labelling reviews with an LLM

Your script
LLM
Validator
DataFrame

rules + JSON schema

1/6Send clear instructions, the allowed labels and the exact output format.

The big ideas

What you need to know

Fix the label set

List every allowed value. Free-form labels become 'delivery', 'Delivery issue' and 'late rider' for the same thing.

Ask for structured output

Request JSON with named fields. Many APIs can enforce a schema, which cuts parsing errors.

Show examples

One to five worked examples, including a tricky one, teach the format better than long explanations.

Validate and sample

Check every output in code and hand-review a random sample. LLMs can be confidently wrong.

See it in code

Walk through the code

text
1You are a data assistant. Classify each customer review.2 3Return only JSON, one object per review:4{"id": <number>, "sentiment": "positive" | "negative" | "neutral", "topic": "delivery" | "food" | "price" | "other"}5 6Example:7Review 0: "Rider was 40 minutes late and the food went cold"8{"id": 0, "sentiment": "negative", "topic": "delivery"}9 10Reviews:111: "Worth every rupee, biryani was perfect"122: "Okay taste but too costly for the portion"

1/4Say who the model is and what the task is in one line.

A reusable labelling prompt. Fill the Reviews section from your DataFrame and parse the reply with json.loads.

Save yourself the pain

Common mistakes

Oops

Pasting customer phone numbers and addresses into a public chatbot.

Do this instead

Strip personal data first, and follow your company's rules on which AI tools are approved.

Oops

Trusting LLM labels without measuring accuracy.

Do this instead

Label 50 to 100 rows yourself and compare. Report agreement before using the labels.

Your mission

Label 30 reviews and check them

~30 min

Quick check

Why list the exact allowed labels in a classification prompt?

Go deeper

  1. 1Use an LLM to label or summarize a small sample of unstructured text data.
  2. 2Practice iterating on a prompt to improve consistency of the output format.
  3. 3Learn where LLM-based labeling is reliable enough to use, and where it still needs human review.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge