500-ai-ml

500-ai-ml is a cursor rule for Cursor from d-padmanabhan/agent-engineering-handbook. It costs 29 tokens per session (9,377 once invoked), scanned A, original, MIT.

A set of rules for building applications that use language models, cloud AI services, and AI agents.

In plain words
What is it for?
It guides retries, fallbacks, validation, prompt versioning, token and cost tracking, logging, safety checks, and output evaluation.
Why use it?
It helps handle unreliable model responses, unexpected inputs, safety risks, usage costs, and changes to prompts or models.

Cursor rule for Cursor

Written for Cursor: a Cursor rule (.mdc).

Good fit It guides retries, fallbacks, validation, prompt versioning, token and cost tracking, logging, safety checks, and output evaluation.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/d-padmanabhan/agent-engineering-handbook/500-ai-ml
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/d-padmanabhan/agent-engineering-handbook

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for 500-ai-ml

README.md
[![agentmods](https://agentmods.dev/badge/rules/d-padmanabhan/agent-engineering-handbook/500-ai-ml.svg)](https://agentmods.dev/rules/d-padmanabhan/agent-engineering-handbook/500-ai-ml)
Your own site
<a href="https://agentmods.dev/rules/d-padmanabhan/agent-engineering-handbook/500-ai-ml"><img src="https://agentmods.dev/badge/rules/d-padmanabhan/agent-engineering-handbook/500-ai-ml.svg" alt="Measured on agentmods" height="20"></a>
Per session 29 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 9,377 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00029 $0.09377
Opus 5 $0.00015 $0.04688
Sonnet 5 $0.00006 $0.01875
Haiku 4.5 $0.00003 $0.00938

Measured 4d ago against content hash 22ba070ebe51, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-07, from the pricing page.

Security

Grade A, and why

500-ai-ml scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

rules/500-ai-ml.mdc · 1,533 lines

How it starts

The opening of the file, as written. The whole thing — 1,533 lines — stays where its author put it; the contents beside it link to each section on GitHub.

AI/ML & LLM Integration Best Practices

Audience: engineers building AI/ML applications, LLM integrations, and AI agents Goal: Reliable, safe, cost-effective AI applications with proper observability and evaluation

AI/ML Philosophy (Core Principles)

Core Principles:

  • "Cost-aware by default" - Monitor token usage, choose appropriate models, implement caching
  • "Reliability over speed" - Retries, fallbacks, timeouts, graceful degradation
  • "Safety first" - Content filtering, prompt injection prevention, guardrails, output validation
  • "Observability is essential" - Log prompts, responses, latency, costs, errors
  • "Evaluate continuously" - Test outputs, measure quality metrics, A/B test prompts
  • "Explicit over implicit" - Clear prompts, explicit instructions, documented assumptions
  • "Fail gracefully" - Fallback strategies, error handling, user-friendly messages
  • "Version everything" - Version prompts, models, evaluation datasets

Applying AI/ML Principles:

# BAD: No error handling, no cost tracking, no safety checks
def generate_text(prompt: str) -> str:
    response = openai.chat.completions.create(
        model="gpt-4",
        messages=[{"role": "user", "content": prompt}]
    )
    return response.choices[0].message.content

# GOOD: Error handling, cost tracking, safety checks
def generate_text(
    prompt: str,
    model: str = "gpt-3.5-turbo",
    max_tokens: int = 1000,
) -> tuple[str, dict]:
    """Generate text with error handling and cost tracking."""
    # Safety check
    if not is_safe_content(prompt):
        raise ValueError("Unsafe content detected")

    try:
        response = openai.chat.completions.create(
            model=model,
            messages=[{"role": "user", "content": prompt}],
            max_tokens=max_tokens,
        )

        content = response.choices[0].message.content

        # Track costs
        metrics = {
            "input_tokens": response.usage.prompt_tokens,
            "output_tokens": response.usage.completion_tokens,
            "total_tokens": response.usage.total_tokens,
            "model": model,
        }

        # Safety check output
        if not is_safe_content(content):
            raise ValueError("Unsafe output generated")

        return content, metrics
    except openai.RateLimitError:
        # Implement retry with backoff
        time.sleep(5)
        return generate_text(prompt, model, max_tokens)
    except Exception as e:
        logger.error(f"Generation failed: {e}")
        raise

Read the full file on GitHub · 1,533 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 1,533 lines · 29 tokens per session scan A 22ba070ebe51

Subscribe to this mod's changes

500-ai-ml is a cursor rule published in the GitHub repository d-padmanabhan/agent-engineering-handbook (16 stars, last pushed yesterday), licensed MIT. It adds 29 tokens to every session and 9,377 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.