agentleFS
LeanMeanCleanAppsLeanMeanCleanApps/CleanModelContextProtocol/.agents/skills/validation/SKILL.md

validation

Skill1 starsChanged 6 days agoMITView on GitHub

How request validation works with FluentValidation and the ValidationBehaviour pipeline, including message wording and the shared paging rules. Use when adding or changing a validator, or when a request needs a new rule.

20 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use testing.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • NVIDIASkill

    testing

    Run Python and Rust tests for physicsnemo-curator using uv + pytest with coverage reporting via pytest-cov, and cargo-nextest for Rust tests. Includes benchmark workflows with pytest-benchmark and criterion.

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

7 rules. 0 are common, 2 are distinctive, and 5 are very specific to this project.

  • 0

    Common

    Most of the 20 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 5

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Create <UseCase>Validator.cs beside the request: public class XValidator : AbstractValidator<XRequest>.

    line 20
  2. Very specific:

    Add one RuleFor per property, each discarded with _ = and qualified with this..

    line 21
  3. Distinctive:

    Write the message for a person reading an API error: what's wrong and what's allowed.

    line 22
  4. Very specific:

    Test every rule (unit-tests, test-design): one valid case, one failing case per rule, and both sides of every boundary in a [Theory].

    line 24
  5. Very specific:

    Use data annotations ([Required], [Range]) on requests.

    line 52
  6. Very specific:

    Check existence in a validator (does this movie exist?).

    line 53
  7. Distinctive:

    Write messages like "Invalid input" or "'Stars' must be between 1 and 5." (the FluentValidation default).

    line 56

“Common” is measured: kept by at least 6 in 10 of the 20 edited versions of this file we could read. “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

Validation

The rule

All input rules live in one place: a FluentValidation validator next to the request in Application. ValidationBehaviour runs every validator for a request before its handler and throws FluentValidation.ValidationException with all failures. Each presentation layer turns that into its own "bad request" shape. Nothing else validates input.

Validators check the shape of a request: ids present, values in range, text the right length. Handlers check anything that needs storage, such as whether a movie exists. So validators are synchronous, take no dependencies and never call a repository.

Validators are found by AddValidatorsFromAssembly in src/Application/DependencyInjection.cs, so a new one needs no registration.

Steps

  1. Create <UseCase>Validator.cs beside the request: public class XValidator : AbstractValidator<XRequest>.
  2. Add one RuleFor per property, each discarded with _ = and qualified with this..
  3. Write the message for a person reading an API error: what's wrong and what's allowed. End with a full stop.
  4. Paged queries use the shared extensions in src/Application/Common/Paging/PagingValidatorExtensions.cs: ValidOffset(), ValidLimit(), ValidSearchTerm().
  5. Test every rule (unit-tests, test-design): one valid case, one failing case per rule, and both sides of every boundary in a [Theory].

Example

// src/Application/Reviews/Commands/CreateReview/CreateReviewValidator.cs
public class CreateReviewValidator : AbstractValidator<CreateReviewCommand>
{
    public CreateReviewValidator()
    {
        _ = this.RuleFor(r => r.AuthorId).NotEqual(Guid.Empty).WithMessage("An author id was not supplied to create the review.");
        _ = this.RuleFor(r => r.MovieId).NotEqual(Guid.Empty).WithMessage("A movie id was not supplied to create the review.");
        _ = this.RuleFor(r => r.Stars).InclusiveBetween(1, 5).WithMessage("A star rating must be between 1 and 5.");
    }
}
// src/Application/Movies/Queries/GetMovies/GetMoviesValidator.cs
_ = this.RuleFor(r => r.Query).ValidSearchTerm();
_ = this.RuleFor(r => r.Offset).ValidOffset();
_ = this.RuleFor(r => r.Limit).ValidLimit();

A rule shared by several requests becomes an extension method on IRuleBuilder<T, TProperty> returning IRuleBuilderOptions<T, TProperty>, with its message inside, like the paging ones.

Don't

  • Use data annotations ([Required], [Range]) on requests.
  • Check existence in a validator (does this movie exist?). That needs storage, so it's the handler's job and throws NotFoundException (errors-and-exceptions).
  • Inject a repository or use MustAsync in a validator.
  • Throw your own ValidationException. Let the behaviour do it.
  • Write messages like "Invalid input" or "'Stars' must be between 1 and 5." (the FluentValidation default). Say it in a sentence.

Check

dotnet test tests/Application.Tests.Unit --filter "FullyQualifiedName~ValidatorTests"

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.