agentleFS
Vimalk0703Vimalk0703/shipworthy/skills/security/bias-detection/SKILL.md

bias-detection

Skill6 starsChanged 8 months agoMITView on GitHub

Use when writing or reviewing code that makes decisions about people — pricing, scoring, ranking, filtering, access control, or content moderation. Detects discriminatory logic and unfair algorithmic patterns.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When any of these appear in scoring, ranking, or pricing logic — flag for review.

    line 50
  2. Distinctive:

    Default sort orders must not systematically disadvantage any group

    line 98
  3. Distinctive:

    Search algorithms must not de-rank results based on proxy attributes

    line 99
  4. Distinctive:

    Every automated decision about a person must be loggable:

    line 111

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Bias Detection

Core Rule

Code that makes decisions about people must be auditable, explainable, and free from proxy discrimination. This applies to pricing algorithms, recommendation engines, content moderation, access control, scoring systems, search ranking, and any logic where different users can receive different outcomes.

High-Risk Code Patterns

Flag these patterns immediately when they appear in decision-making code:

1. Protected Attribute Usage

Direct use of protected attributes in decision logic:

// BAD — direct discrimination
function calculateRate(user: User): number {
  if (user.gender === 'female') return baseRate * 1.2;  // FLAG
  if (user.age > 60) return baseRate * 1.5;              // FLAG
  if (user.zipCode === '10451') return baseRate * 1.8;   // FLAG — proxy for race/income
  return baseRate;
}

// GOOD — decision based on relevant behavioral attributes
function calculateRate(account: Account): number {
  const riskScore = calculateRiskFromBehavior(account.history);
  return baseRate * riskMultiplier(riskScore);
}

2. Proxy Variable Detection

Variables that correlate with protected attributes:

Proxy VariableCorrelates WithWhy It's Risky
Zip code / postal codeRace, incomeRedlining by another name
First name / last nameRace, ethnicity, genderName-based discrimination
Language preferenceNational origin, ethnicityExclusion of non-dominant groups
Device type / browserIncome, ageEconomic discrimination
School / university nameRace, socioeconomic statusEducational elitism
Profile photo analysisRace, gender, age, disabilityVisual discrimination

When any of these appear in scoring, ranking, or pricing logic — flag for review.

3. Threshold Bias

Hard-coded thresholds that disproportionately affect groups:

// BAD — arbitrary threshold without justification
function isEligible(user: User): boolean {
  return user.creditScore > 720;  // FLAG — threshold disproportionately excludes certain demographics
}

// BETTER — document threshold justification and measure impact
function isEligible(user: User): boolean {
  // Threshold: 650 based on default rate analysis (see decision doc #1234)
  // Disparate impact tested quarterly — last review 2026-01-15
  return user.creditScore > CREDIT_THRESHOLD;
}

4. Training Data Assumptions

Code that embeds assumptions from biased data:

// BAD — hardcoded assumption from biased historical data
const DEFAULT_SALARY = role === 'engineer' ? 120000 : 65000;

// BAD — gendered defaults
const title = user.name.endsWith('a') ? 'Ms.' : 'Mr.';

// GOOD — no assumptions about defaults; let the user specify
const title = user.preferredTitle ?? '';

Bias Categories to Check

Decision Fairness

  • Equal treatment: Same inputs produce same outputs regardless of group membership
  • Equal opportunity: Qualified individuals from all groups have equal chance of positive outcome
  • Demographic parity: Positive outcomes distributed proportionally across groups (when applicable)

Content Moderation Bias

  • Moderation rules must not disproportionately flag content from specific cultural or linguistic groups
  • Keyword blocklists must be reviewed for cultural bias
  • Automated content decisions must have human appeal paths

Search and Ranking Bias

  • Default sort orders must not systematically disadvantage any group
  • Search algorithms must not de-rank results based on proxy attributes
  • Recommendation systems must measure and report diversity metrics

Pricing and Access Bias

  • Dynamic pricing must not correlate with protected attributes
  • Feature gating must not create discriminatory access patterns
  • Rate limiting must be uniform across demographic groups

Implementation Guardrails

1. Decision Logging

Every automated decision about a person must be loggable:

interface DecisionLog {
  decisionType: string;       // 'pricing' | 'eligibility' | 'ranking' | 'moderation'
  inputFeatures: string[];    // which features were used (NOT their values for PII reasons)
  outcome: string;            // the decision made
  modelVersion: string;       // which version of the logic made this decision
  timestamp: string;
  appealable: boolean;        // can the user challenge this decision?
}

2. Disparate Impact Testing

For any scoring or classification system, implement a test:

it('pricing does not show disparate impact by zip code', () => {
  const results = ZIP_CODES_BY_DEMOGRAPHIC.map(zip => ({
    zip,
    price: calculatePrice({ ...baseUser, zipCode: zip }),
  }));

  const groupAAvg = average(results.filter(r => GROUP_A_ZIPS.includes(r.zip)).map(r => r.price));
  const groupBAvg = average(results.filter(r => GROUP_B_ZIPS.includes(r.zip)).map(r => r.price));

  // Four-fifths rule: ratio must be > 0.8
  expect(Math.min(groupAAvg, groupBAvg) / Math.max(groupAAvg, groupBAvg)).toBeGreaterThan(0.8);
});

3. Explainability Requirement

Decision-making code must support explanation:

// Every decision function should have an explain variant
function calculateEligibility(user: User): { eligible: boolean; reasons: string[] } {
  const reasons: string[] = [];

  if (user.accountAge < 30) reasons.push('Account less than 30 days old');
  if (user.verificationStatus !== 'verified') reasons.push('Identity not verified');

  return {
    eligible: reasons.length === 0,
    reasons,
  };
}

Regulatory Context

RegulationRequirementApplies When
EU AI ActHigh-risk AI systems require bias audits, transparency, human oversightScoring, hiring, credit, law enforcement
ECOA (US)Cannot discriminate in credit decisionsAny credit/lending logic
Fair Housing ActCannot use protected attributes in housing decisionsReal estate, rental platforms
GDPR Art. 22Right to explanation for automated decisionsAny automated decision affecting EU residents
NYC Local Law 144Bias audits required for automated employment toolsHiring, promotion, recruiting algorithms

Code Review Checklist

  • No protected attributes (gender, race, age, religion, disability) in decision logic
  • Proxy variables identified and justified or removed
  • Hard-coded thresholds documented with justification and impact analysis
  • Decision logging implemented for user-affecting automated decisions
  • Disparate impact test exists for scoring/classification systems
  • Explainability: users can understand why a decision was made about them
  • Content moderation rules reviewed for cultural/linguistic bias
  • Default values do not encode demographic assumptions
  • Appeal/override mechanism exists for automated decisions

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.