# Add Input Validation to an Actix Web App from a Linear Issue

Yes. An agent reads the labelled Linear issue, adds validator checks to an Actix Web form handler with a flash message per failure, tests it and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-input-validation/actix/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the issue and then the handler it names. In a workspace shaped like actix/examples the target is `basics/todo`, a small Actix Web 4.11 app on edition 2024 and `rust-version` 1.98 from the workspace `Cargo.toml`, with `actix-session` 0.11 on a cookie store, `actix-files`, Tera 2 templates, `sqlx` 0.9 on SQLite with `runtime-tokio` and `tls-rustls`, `dotenvor` and `env_logger`. `src/main.rs` builds the `App` with `Logger`, the session middleware and `ErrorHandlers` for 400, 404 and 500 that serve `static/errors/*.html`, and registers `GET /`, `POST /todo` and `POST /todo/{id}`. `src/api.rs` holds the handlers: `create` takes a `web::Form<CreateForm>` with a single `description: String`, rejects only an empty string with `FlashMessage::error("Description cannot be empty")`, and otherwise inserts through `db::create_task`; `update` dispatches on a `_method` field with `put` and `delete` and answers 400 for anything else. `src/session.rs` stores one `FlashMessage` with a `kind` and a `message` under the `flash` key, and `templates/index.html.tera` renders it as `field-{{msg[0]}}` classes on the input. The migration in `migrations/` declares `description VARCHAR NOT NULL` with no length, and the README says the query macros check against `todo.db` with `SQLX_OFFLINE=false`.

The issue asks for real validation, so the agent adds the `validator` crate with its `derive` feature to `basics/todo/Cargo.toml`, the same crate and version the workspace's `json/json-validation` example already uses, and derives `Validate` on `CreateForm`: `description` gets `#[validate(length(min = 1, max = 200))]` and a `custom` function that rejects a string that is only whitespace, trimming before the length check so a padded empty field fails the same way. The `create` handler calls `params.validate()`, turns the first `ValidationErrors` entry into a `FlashMessage::error` whose text names the field and the rule in plain words, and redirects to `/` with 302 exactly as the empty-string branch does today, so the template needs no change. `UpdateParams` gets a positive-id check so `/todo/0` and a negative id answer 400 through the existing `bad_request` handler rather than running a query, and `UpdateForm` validates `_method` against the two accepted values before the match.

Tests did not exist for this example, so the agent adds `src/tests.rs` behind `#[cfg(test)]` using `actix_web::test` and `actix-test` from the workspace dependencies. The cases post `description=` and `description=%20%20`, follow the redirect and assert the flash message in the session cookie; post a 201-character description and assert the length message; post a 20-character description and assert a row appears through `Task::all`; and post `_method=patch` to `/todo/1` and assert 400. The database is the SQLite file the README's `sqlx database create` and `sqlx migrate run` steps produce, so the agent runs those with `DATABASE_URL=sqlite://./todo.db` first, exactly as `.github/workflows/ci.yml` does before `cargo test --workspace`.

It runs `cargo check -p todo`, `cargo clippy -p todo --all-targets --all-features` and `cargo test -p todo -- --nocapture` until all three are clean, formats with `cargo +nightly fmt` as the `justfile` does, regenerates the offline query metadata with `cargo sqlx prepare` if a query changed, and then pushes a branch and opens a pull request that quotes the issue and links back to it.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "A Linear issue labelled agent says: \"Validate the todo form. Reject blank or whitespace-only descriptions and anything over 200 characters with a clear message, and refuse bad ids and unknown _method values before they reach the database.\" Do the work in basics/todo of this repository with the validator crate the workspace already uses, keep the existing flash-message redirect so the template does not change, add tests with actix_web::test that cover each rule, run the sqlx setup from the README and then cargo check, clippy and test for the package, and open a pull request that links back to the issue.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request on its own branch. The diff touches `basics/todo/Cargo.toml` for the `validator` dependency, `basics/todo/src/api.rs` for the derives, the `validate()` calls and the id and method checks, a new `basics/todo/src/tests.rs` with its `mod tests;` line in `main.rs`, and `basics/todo/.sqlx/` if the query metadata moved. The template, the migration and the session code are unchanged. The description quotes the issue, lists each rule with the message a user sees, and links the Linear issue.

The checks are the proof. The repository's `ci.yml` creates the SQLite database, runs the migrations and then `cargo test --workspace --all-features` on every pull request, so the new cases run there under stable Rust, and `clippy-fmt.yml` runs Clippy and the formatter. The session's trajectory at `GET /o/{org}/sessions/{id}/messages` keeps every `cargo` invocation with its output, so a reviewer sees the cases pass before the workflow does.

Before merging, a reviewer checks that the 200-character limit matches what the product wants, since the column has no length of its own, that whitespace-only input fails on the trimmed value and not the raw one, and that the error messages read as sentences in the flash banner. A reviewer running the app follows the README's `sqlx` steps, posts a blank description and sees the message in the input's error style.

## Run it on every Linear issue labelled agent

Sign in to Linear once with `POST /me/connections {"type": "app", "name": "linear"}` and finish the `authorize_url` in the console. Add an automation to the Project with this prompt and a `linear` trigger on `linear.issue.labeled`, filtered to the `agent` label; labelling an issue appends it after the prompt and starts a run in the Project's repository, and the pull request links back to the issue. An automation run has its own `max_runs_per_hour` cap and is not tied to an API key.

From a script, send `POST /o/{org}/sessions` with the repository in `resources` and the issue URL `https://linear.app/<workspace>/issue/ENG-42` beside it, read through your Linear connection. Give the key a `webhook_url` and Rush POSTs `run.completed` with `session_url` when the turn ends, so the script can comment the pull request link on the issue.

## Why run it on Rush?

Validation work in a Rust web app is small code and a long feedback loop: the `sqlx` query macros need a database to check against, Clippy has opinions about every `unwrap`, and a test that follows a redirect and reads a session cookie takes a few tries to get right. On Rush the run does all of that in its own cloud sandbox with its own `todo.db`, following the exact setup the README and the CI workflow describe, while your checkout and your `target/` directory stay untouched.

Each labelled issue gets its own sandbox and its own pull request, with the diff, the Linear link and a trajectory that keeps every `cargo test` run with its output. The proof of the change is the change itself, plus the CI the repository already runs on every pull request.

## Frequently asked questions

### Why the validator crate rather than hand-written checks?

The workspace already depends on `validator` 0.21 with `derive` in its `json/json-validation` example, so the rules live as attributes on the form struct and read at a glance. A `custom` validator handles the whitespace case the built-in `length` rule cannot, and nothing else in the dependency tree changes.

### Does the template or the migration change?

No. The handler already redirects with a flash message for the empty case, and the new rules reuse that path, so `index.html.tera` renders them with the same `field-error` class. The `description` column stays `VARCHAR NOT NULL`; the 200-character limit is enforced in the handler, and the pull request says so.

### How are the tests run when sqlx checks queries at compile time?

The same way the repository's CI does: `sqlx database create` and `sqlx migrate run` with `DATABASE_URL=sqlite://./todo.db` before `cargo test`. If a query changed, the agent runs `cargo sqlx prepare` so `.sqlx/` matches and `SQLX_OFFLINE=true` builds still work, as the README describes.

### What does a user see on a failed submit?

A 302 back to `/` with the message in the flash banner above the input, in the same style the empty-description case uses today: for example that the description must be between 1 and 200 characters. The messages are listed in the pull request description so copy can be changed in review.

### What if the issue names a different limit?

The agent uses the number in the issue. When the issue gives none, it picks 200, states it in the pull request and marks it as the one value to confirm. A follow-up on the same session changes it without a second run.

## More Actix Web jobs

- [Add JWT Authentication to an Actix Web API](https://getrush.ai/run/add-jwt-auth/actix/)
- [Add OpenAPI Docs to an Actix Web API](https://getrush.ai/run/add-openapi-docs/actix/)
- [Add OpenTelemetry Tracing to an Actix Web App](https://getrush.ai/run/add-opentelemetry/actix/)

## The same job on other stacks

- [Add Input Validation to an aiohttp App](https://getrush.ai/run/add-input-validation/aiohttp/)
- [Add Request Validation to an API Gateway in AWS CDK](https://getrush.ai/run/add-input-validation/aws-cdk/)
- [Add Input Validation to an Axum API](https://getrush.ai/run/add-input-validation/axum/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
