Prompt Overview¶
In rac4os a prompt is not a string in a config file. Each classifier is driven by a
dspy.Signature whose docstring is the system prompt and whose fields are the
input/output contract. Both live in one place, because renaming an output field changes
what the prompt is allowed to refer to.
What you see on this page is rendered from the installed package, so it is exactly what the model receives — it cannot drift from the code.
Signature table¶
| Dataset | Signature |
|---|---|
COICOP_2018 |
CoicopRAGChainOfThoughtSignature |
ICATUS_2016 |
IcatusRAGChainOfThoughtSignature |
SEA_2021 |
SeaRAGChainOfThoughtSignature |
SEA_2021_REPHRASED |
SeaRAGChainOfThoughtSignature |
The Rephrase step has its own signatures — see Rephrasing signatures.
Each entry in RAGChainOfThought.CONFIGS bundles the signature with the two field names
the pipeline needs:
"SEA_2021": {
"signature": registry.SeaRAGChainOfThoughtSignature,
"query_field": "input_expense",
"context_field": "retrieved_candidates",
}
Commonly used instructions¶
The bundled docstrings are written around a few recurring elements. They are worth copying into a signature of your own:
| Element | What it does |
|---|---|
| Role and task | names the taxonomy and the unit being classified |
| Reasoning protocol | the order in which candidates are compared, and what breaks a tie |
| Hierarchy guidance | tells the model to judge on includes rather than on the short label |
| Target level | states which level a code may be emitted at |
| Grounding constraint | forbids emitting a code that was not in the candidate set |
| Output discipline | what belongs in the code field, what belongs in the explanation |
Two variants of the hierarchy guidance exist in the bundled prompts, matching the two
augmentation setups: one instructs the model to base its
judgment on the includes of each candidate, the other states that the description is
the only anchor available. They differ in that passage and nowhere else.
Writing your own¶
import dspy
class SpendRAGCoTSignature(dspy.Signature):
"""Classify an internal spend item into the SPEND taxonomy.
You are given one item as recorded by a member of staff, plus candidate categories
retrieved from the taxonomy. Choose exactly one.
Reasoning protocol:
- Read every candidate before judging, comparing the item against the `includes`
entries, which enumerate what a category actually covers.
- Where two candidates both fit, prefer the one whose `includes` names the item's
concrete form.
- Never emit a code that is not in the candidate list.
The target level is level 3.
"""
input_item: str = dspy.InputField(desc="the item text to classify, as recorded")
retrieved_candidates: str = dspy.InputField(desc="candidate categories as JSON")
spend_code: str = dspy.OutputField(desc="the code of the chosen category")
explanation: str = dspy.OutputField(desc="why this category and not the others")
Tip
Field names are part of the prompt. spend_code tells the model more than code
does, and input_item more than query. Rename fields when you adapt a signature to
a new taxonomy rather than keeping another classification's vocabulary.
Changing a prompt needs no registry edit at all — pass the signature straight to
BaseRAGCoT and A/B two versions in one script. Promote it into CONFIGS once it is
worth keeping.
Bundled signatures¶
Chain-of-thought signatures¶
rac4os.rag.registry.CoicopRAGChainOfThoughtSignature
¶
Bases: Signature
Classify a household expense into a single COICOP code by reasoning over a set of pre-retrieved candidate codes, rather than relying on memorized codes.
COICOP is a hierarchy of codes (division -> group -> class -> subclass), e.g. 01 -> 01.1 -> 01.1.1 -> 01.1.1.1. A valid final answer is a real code present in the retrieved candidates; prefer the most specific code that correctly covers the expense.
Reasoning protocol: 1. Identify the essence of the expense: what good or service was actually purchased. Note any detail that affects placement (state/form of the item, purpose, whether it is a good vs. a service). 2. Compare the expense against every retrieved candidate's description and notes: - Read the 'includes' and 'alsoIncludes' notes to confirm a match. - Read the 'excludes' notes carefully: they explicitly redirect items that look like they belong here but are classified elsewhere, and usually name the correct code. If the redirected code is itself among the candidates, prefer it. 3. Before committing, make sure the chosen code's notes do not exclude this expense. 4. If no candidate fits specifically, choose the most appropriate "other" / residual candidate within the correct branch rather than guessing a code from a different branch.
Rules: - Never invent or guess a code from memory. The final coicop_code must be an exact code string that appears in retrieved_candidates, not a paraphrase or a made-up variant. - The target level for the classification of the expense is 4; always try to find a level-4 code among the candidates. - When evidence is ambiguous, prefer the interpretation supported by the includes/excludes notes over intuition.
Source code in rac4os/rag/registry.py
rac4os.rag.registry.IcatusRAGChainOfThoughtSignature
¶
Bases: Signature
Classify a time-use activity into a single ICATUS 2016 code by reasoning over a set of pre-retrieved candidate codes, rather than relying on memorized codes.
ICATUS 2016 (International Classification of Activities for Time-Use Statistics) is a hierarchy of codes (major division -> division -> group), e.g. 1 -> 11 -> 110. A valid final answer is a real code present in the retrieved candidates; prefer the most specific code that correctly covers the activity.
Reasoning protocol: 1. Identify the essence of the activity: what the person was actually doing. Note any detail that affects placement (whether it was done for pay or profit, for own final use, as an unpaid service for the household, as volunteering, or as a personal activity; and for whom it was performed). 2. Compare the activity against every retrieved candidate's title and notes: - Read the 'includes' and 'examples' notes to confirm a match. - Read the 'excludes' notes carefully: they explicitly redirect activities that look like they belong here but are classified elsewhere, and usually name the correct code. If the redirected code is itself among the candidates, prefer it. 3. Before committing, make sure the chosen code's notes do not exclude this activity. 4. If no candidate fits specifically, choose the most appropriate "other" / residual candidate within the correct branch rather than guessing a code from a different branch.
Rules: - Never invent or guess a code from memory. The final icatus_code must be an exact code string that appears in retrieved_candidates, not a paraphrase or a made-up variant. - The target level for the classification of the activity is 3; always try to find a level-3 code among the candidates. - When evidence is ambiguous, prefer the interpretation supported by the includes/excludes notes over intuition.
Source code in rac4os/rag/registry.py
rac4os.rag.registry.SeaRAGChainOfThoughtSignature
¶
Bases: Signature
Classify a private-household income or expenditure item into a single SEA 2021 code by reasoning over a set of pre-retrieved candidate codes, rather than relying on memorized codes.
The SEA 2021 (Systematik der Einnahmen und Ausgaben der privaten Haushalte, Statistisches Bundesamt) is a hierarchy of numeric codes across THREE parts: Abteilung 00 (Einnahmen / household income); Abteilungen 01-15 (Verwendungszwecke des Individualkonsums / individual consumption, mirroring COICOP 2018; households 01-13, private non-profit institutions 14, government 15); and Abteilung 16 (Ausgaben ohne Individualkonsum / non-consumption expenditure: taxes, social- and private-insurance contributions, membership fees, donations, loan repayment/interest, and formation of tangible/financial wealth). Levels: Abteilung (2 digits) -> Gruppe (3) -> Klasse (4) -> Unterklasse (5) -> Kategorie (6) -> Unterkategorie (7), e.g. 01 -> 011 -> 0111 -> 0111 1 -> 0111 10 -> 0111 101, written with a space after the 4th digit. A valid final answer is a real code present in the retrieved candidates; prefer the most specific code that correctly covers the item.
Reasoning protocol: 1. Identify the essence of the item. First decide which of the three parts it belongs to: INCOME (Einnahme -> Abteilung 00), a CONSUMPTION purchase of a good/service (Individualkonsum -> 01-15), or a NON-CONSUMPTION outflow such as a tax, contribution, donation, loan repayment or saving/investment (-> Abteilung 16). This choice is the most consequential (e.g. an insurance premium is 16, a household appliance is 05). Note any consumption detail that affects placement: home vs. immediate consumption (the latter usually -> 1111), state/form (fresh, frozen, prepared/Fertiggericht), good vs. service. 2. Compare the item against every retrieved candidate's Bezeichnung and notes: - Read the 'Eingeschlossen sind' (includes) notes to confirm a match. - Read the 'Ausgeschlossen sind' (excludes) notes carefully: they explicitly redirect items that look like they belong here but are classified elsewhere, and usually name the correct code in parentheses. If the redirected code is itself among the candidates, prefer it. 3. Before committing, make sure the chosen code's notes do not exclude this item. 4. If no candidate fits specifically, choose the most appropriate "Andere ... , a.n.g." (residual) candidate within the correct branch rather than guessing a code from a different branch.
Rules: - Never invent or guess a code from memory. The final sea_code must be an exact code string that appears in retrieved_candidates, not a paraphrase or a made-up variant, formatted with the space after the 4th digit (e.g. '0111 101'). - The target level for the classification of the item is 5 (the Unterklasse); always try to find a level-5 code among the candidates, descending to Kategorie/Unterkategorie (levels 6-7) only when the evidence clearly supports a more specific base unit. - When evidence is ambiguous, prefer the interpretation supported by the Eingeschlossen/Ausgeschlossen notes over intuition.
Source code in rac4os/rag/registry.py
Rephrasing signatures¶
Used by Rephrase-Retrieve-Respond. These do not classify — they restate the item in the vocabulary of the labels.
rac4os.rag.registry.CoicopRephrasingSignature
¶
Bases: Signature
Rewrite a household expense into a search query that reads like a COICOP 2018 category title, so that semantic search over those titles retrieves the right candidate codes. You are NOT classifying the expense: never output a code and never decide between categories.
The search index contains only the short English titles of the COICOP codes, for example "Eggplants (aubergines), fresh or chilled", "Ice, ice cream and sorbets", "School uniforms", "Repair of electric appliances for personal care", "Life and accident insurance". Raw expense text — receipt abbreviations, brand names, shop wording, quantities — is far from these titles in embedding space. Your job is to translate the expense into the vocabulary of these titles.
Rewriting protocol: 1. Work out what was actually bought. Expand receipt shorthand and abbreviations (e.g. "BIO VOLLM 3,8%" -> organic whole milk) and replace brand or product names with the generic good or service they stand for (e.g. "Nutella" -> chocolate hazelnut spread; "Netflix" -> video streaming subscription service). Translate non-English input into English. 2. Name it with the plain generic term an official classification would use. Where you are certain of the broader product group, put it first and the specific item after it (e.g. "vegetables, fresh or chilled: eggplant"). 3. Keep every attribute that changes where the item is classified: - state or form: fresh, chilled, frozen, dried, preserved/canned, ready-made meal; - good vs. service: purchase vs. repair, rental, hire, installation, maintenance, insurance, subscription, fee; - consumed at home vs. served in a restaurant, café or canteen; - new vs. second-hand; - intended user or purpose where stated (children, pets, vehicle, school, sport, medical use). 4. Drop everything that does not change placement: brand, shop, quantity, pack size, price, date, promotional or marketing wording.
Rules: - Output one short noun phrase (about 2-12 words) in English. No full sentences, no explanations, no code numbers, no "(ND)"/"(S)" suffixes. - Do not force a category word you are unsure of: a wrong broader term pulls retrieval into the wrong branch. When in doubt, describe the item itself generically and leave the category out. - Do not add facts that are not in, or clearly implied by, the input. - If the input is already a clean generic description, return it almost unchanged.
Source code in rac4os/rag/registry.py
rac4os.rag.registry.IcatusRephrasingSignature
¶
Bases: Signature
Rewrite a time-use activity into a search query that reads like an ICATUS 2016 activity title, so that semantic search over those titles retrieves the right candidate codes. You are NOT classifying the activity: never output a code and never decide between categories.
The search index contains only the short English titles of the ICATUS codes, for example "Eating meals/snack", "Travelling and commuting for employment", "Agriculture, forestry, fishing and mining for own final use", "Providing paid business and professional services in households and household enterprises", "Travelling time related to unpaid volunteer, trainee and other unpaid work". These titles are organised less by WHAT the person did than by the ECONOMIC NATURE of the activity and FOR WHOM it was done. Raw diary entries ("did the dishes", "drove Tom to school", "Mathe-Nachhilfe gegeben") are far from these titles in embedding space. Your job is to translate the entry into their vocabulary.
Rewriting protocol: 1. Work out what the person was actually doing. Expand shorthand and translate non-English input into English. 2. Make the economic nature explicit whenever the input states or clearly implies it: for pay or profit (employment, own business), for own final use (producing goods or services for one's own household), unpaid domestic service or unpaid caregiving for household or family members, unpaid volunteer work for others, learning, or a personal / leisure / self-care activity. 3. Make the beneficiary explicit when stated: oneself, a child of the household, a dependent or non-dependent adult household or family member, another household, the community or an organisation. 4. If the entry is travel, say that it is travelling and what it was related to (e.g. "travelling time related to childcare: taking child to school"). 5. Drop names of people and places, times, durations and other detail that does not change placement.
Rules: - Output one short phrase (about 3-15 words) in English, in the style of an ICATUS title. No full sentences, no explanations, no code numbers. - Do not invent a pay status or beneficiary that is not stated or clearly implied; a wrong one pulls retrieval into the wrong major division. When unknown, describe the activity itself and leave it out. - If the input is already a clean generic description, return it almost unchanged.
Source code in rac4os/rag/registry.py
rac4os.rag.registry.SeaRephrasingSignature
¶
Bases: Signature
Rewrite a private-household income or expenditure item into a German search query that reads like an SEA 2021 Bezeichnung (category label), so that semantic search over those labels retrieves the right candidate codes. You are NOT classifying the item: never output a code and never decide between categories.
The search index contains only the German labels (Bezeichnungen) of the SEA 2021 codes, for example "Steinobstkonserven, z.B. Pflaumen-, Mirabellen-, Kirsch-, Pfirsich- und Aprikosenkonserven", "Gartenmöbel (ohne Sonnenschirme ...), z.B. Gartenbänke, Balkonmöbel", "Versicherungsdienstleistungen", "Kredite für Hochzeiten, Familienfeiern u.Ä.", "Gastronomie- und Beherbergungsdienstleistungen". Many labels name a generic group followed by typical examples ("z.B. ..."). Raw items — receipt abbreviations, brand names, bank-statement text, quantities — are far from these labels in embedding space. Your job is to translate the item into their vocabulary.
Rewriting protocol: 1. Work out what the item is. Expand receipt and bank-statement shorthand (e.g. "BIO VOLLM 3,8%" -> Bio-Vollmilch; "LASTSCHRIFT ALLIANZ KFZ" -> Beitrag Kfz-Haftpflichtversicherung) and replace brand or product names with the generic good or service (e.g. "Nutella" -> Nuss-Nougat-Creme; "Netflix" -> Video-Streaming-Abonnement). Translate non-German input into German. 2. Make the direction of the money flow explicit when it is clear: an Einnahme (income: Lohn/Gehalt, Rente, Kindergeld, Mieteinnahme, Zinsen, ...), a Konsumausgabe for a good or service, or an Ausgabe ohne Konsum (Steuer, Sozialversicherungs- oder Versicherungsbeitrag, Mitgliedsbeitrag, Spende, Tilgung oder Zinsen eines Kredits, Sparen/Geldanlage). Use the wording of that area (e.g. "Beitrag zur ...", "Einnahmen aus ...", "Tilgung ..."). 3. Name it with the generic term an official German classification would use. Where you are certain of the broader group, write it first and the specific item after it, mirroring the "Gruppe, z.B. Artikel" pattern of the labels (e.g. "Steinobstkonserven, Pfirsichkonserve"). 4. Keep every attribute that changes placement: - Zustand/Form: frisch, gekühlt, tiefgefroren, getrocknet, Konserve, Fertiggericht; - Ware vs. Dienstleistung: Kauf vs. Reparatur, Miete, Leihe, Installation, Wartung, Gebühr, Abonnement; - Verzehr zu Hause vs. im Restaurant, Café, Imbiss oder in der Kantine; - neu vs. gebraucht; - Verwendungszweck oder Nutzer, wenn genannt (Kinder, Haustier, Fahrzeug, Schule, Sport, Gesundheit). 5. Drop everything that does not change placement: brand, shop, quantity, pack size, price, date, IBAN, reference numbers, promotional wording.
Rules: - Output one short German noun phrase (about 2-12 words). No full sentences, no explanations, no code numbers. - Do not force a group word or a money-flow direction you are unsure of: a wrong one pulls retrieval into the wrong Abteilung. When in doubt, describe the item itself generically and leave it out. - Do not add facts that are not in, or clearly implied by, the input. - If the input is already a clean generic German description, return it almost unchanged.