Skip to content

role-clarity โ€” Role Definition Check โ€‹

Severity: WARN ยท Auto-fix: No ยท Category: ๐Ÿ—๏ธ Structure

What It Does โ€‹

Checks that the prompt defines a role or persona for the model. Prompts without a role rely on the model's default behavior, which varies between model versions and can produce inconsistent tone, expertise level, and format.

Trigger Conditions โ€‹

Three conditions must all be true for this rule to fire

  1. The prompt is at least 30 words long โ€” short prompts aren't expected to have a role definition
  2. The prompt contains instructional language (words like you, respond, answer, help, assist, always, never, must, should)
  3. The prompt does not contain a recognized role definition phrase

This means the rule won't fire on a simple 5-word translation request, only on prompts that are clearly giving behavioral instructions to the model.

Recognized Role Phrases โ€‹

The rule considers any of these as a valid role definition:

PhraseExample
you are / you'reYou are a helpful assistant.
act asAct as a senior Python engineer.
your role isYour role is to review code.
you will serve asYou will serve as a technical reviewer.
you work asYou work as a customer support agent.
your job isYour job is to extract key information.
your task isYour task is to summarize the document.
you are responsible forYou are responsible for validating inputs.
you specialize inYou specialize in financial analysis.

Example โ€‹

No role โ€” fires

Always respond in formal English. You must answer questions about our product
only. Never discuss competitor products. Keep responses under 3 sentences.

Finding:

[ WARN ] role-clarity (line -)
  No role or persona defined. Add 'You are a [role]...' to improve
  output consistency.

This has 30+ words and clear instructions (always, must, never) โ€” but no role.

With role โ€” passes

You are a formal customer support specialist for Acme Corp.
Always respond in formal English. You must answer questions about our product
only. Never discuss competitor products. Keep responses under 3 sentences.

False Positives โ€‹

Data extraction prompts โ€” a prompt like Extract all dates from the following text and return JSON is 14 words with no instructional keywords (you, respond, must). It won't trigger despite having no role.

Prompts with implicit role via structure โ€” if you use <role>Senior Python Engineer</role> in XML, this is NOT currently recognized (the rule only checks for the phrases above). Add You are a senior Python engineer. to be safe.

Configuration โ€‹

yaml
rules:
  role_clarity: true   # or false to disable

Demote to INFO if role-less prompts are acceptable in your use case:

yaml
rules:
  role_clarity:
    enabled: true
    level: info

Why Roles Matter โ€‹

A role definition:

  • Sets the model's implicit expertise level and calibrates its vocabulary
  • Reduces hallucination by anchoring the model's "perspective"
  • Improves consistency when the same prompt runs across different model versions
  • Lets you control formality and domain specificity without spelling it out in every sentence

Without a role, the same prompt can produce dramatically different output between GPT-4o and GPT-3.5, or between Claude 3 Haiku and Claude 3.5 Sonnet.

Released under the Apache 2.0 License.