Automated summary
This skill documents Skrift's form system, combining Pydantic validation with CSRF protection, template rendering, and hook integration in a Litestar application.
Strengths
- Shows a complete GET/POST controller flow with validation, redirect, and error re-rendering.
- Explains field customization through json_schema_extra, including labels, widgets, choices, and HTML attributes.
- Explicitly covers CSRF verification and single-use token rotation.
- Provides concrete examples for both FormModel and the @form decorator.
Limitations
- Tightly coupled to Skrift and Litestar, so it is not portable to other frameworks.
- Requires familiarity with Pydantic and server-side template rendering.
- Does not fully detail template implementation or hook behavior beyond event names.
Use it when building or modifying server-rendered forms in a Skrift/Litestar app with Pydantic validation and CSRF protection.
Avoid it for pure API forms, single-page applications, or projects that do not use Skrift.
Security analysis
SafeThe skill is purely documentation for a form library, containing no executable commands or dangerous instructions. It promotes secure practices like CSRF protection and HMAC comparison.
No concerns found
How this analysis is madeExamples
Create a Skrift contact form with name, email, subject select, message textarea, and newsletter checkbox, including CSRF protection and GET/POST Litestar controller handlers.Add a CSRF-protected newsletter signup form using Skrift's @form decorator and render it in a Litestar template.Customize Skrift form fields with labels, help text, input types, select choices, textarea rows, and HTML attributes using json_schema_extra.name: skrift-forms description: "Skrift form system — Pydantic-backed forms with CSRF protection, template rendering, and hook integration."
Skrift Form System
Skrift forms combine Pydantic validation with CSRF protection, template rendering, and hook integration.
Architecture
FormModel/BaseModel → Form(model, request) → validate() → hooks → data
│ │ │ │
│ │ │ ├─ form_{name}_validated
│ │ │ └─ form_validated
│ │ │
│ │ ├─ CSRF verify (hmac.compare_digest)
│ │ ├─ Token rotation (single-use)
│ │ ├─ Checkbox injection (bool fields)
│ │ └─ Pydantic validation
│ │
│ ├─ render() → Template("form", name).try_render()
│ ├─ csrf_field() → hidden input
│ ├─ fields → dict[str, BoundField]
│ └─ errors → dict[str, str]
│
└─ Registered in _form_registry (by form_name)
Defining Forms
FormModel (auto-registers)
from skrift.forms import FormModel
from pydantic import Field, EmailStr
class ContactForm(FormModel, form_name="contact"):
name: str
email: EmailStr
message: str = Field(json_schema_extra={"widget": "textarea"})
@form() Decorator (registers a plain BaseModel)
from pydantic import BaseModel
from skrift.forms import form
@form("newsletter", action="/subscribe", method="post")
class NewsletterForm(BaseModel):
email: str
Field Customization via json_schema_extra
| Key | Values | Purpose |
|-----|--------|---------|
| label | str | Custom label text |
| widget | "textarea", "select", "checkbox" | Widget type |
| input_type | "email", "password", etc. | HTML input type |
| help_text | str | Help text below field |
| choices | list[tuple[str, str]] | Options for select widget |
| attrs | dict[str, str] | Extra HTML attributes |
Full example:
class ContactForm(FormModel, form_name="contact"):
name: str = Field(json_schema_extra={
"label": "Your Name",
"attrs": {"placeholder": "Jane Doe"},
})
email: EmailStr = Field(json_schema_extra={
"label": "Email Address",
"input_type": "email",
"help_text": "We'll never share your email.",
})
subject: str = Field(json_schema_extra={
"widget": "select",
"choices": [
("general", "General Inquiry"),
("support", "Technical Support"),
],
})
message: str = Field(json_schema_extra={
"widget": "textarea",
"attrs": {"rows": "6"},
})
subscribe: bool = Field(default=False, json_schema_extra={
"label": "Subscribe to newsletter",
})
Controller GET/POST Pattern
from litestar import Controller, get, post, Request
from litestar.response import Template as TemplateResponse, Redirect
from skrift.forms import Form
class ContactController(Controller):
path = "/contact"
@get("/")
async def show(self, request: Request) -> TemplateResponse:
form = Form(ContactForm, request)
return TemplateResponse("contact.html", context={"form": form})
@post("/")
async def submit(self, request: Request) -> TemplateResponse | Redirect:
form = Form(ContactForm, request)
if await form.validate():
# form.data is a validated ContactForm instance
await process_contact(form.data)
return Redirect("/contact?thanks=1")
return TemplateResponse("contact.html", context={"form": form})
Template Rendering
Automatic
{{ form.render() }}
{{ form.render(submit_label="Send") }}
Manual
<form method="{{ form.method }}">
{{ form.csrf_field() }}
{% for field in form %}
{{ field.label_tag() }}
{{ field.widget() }}
{% endfor %}
<button type="submit">Send</button>
</form>
Custom Form Template
Template hierarchy: form-{name}.html → form.html → programmatic fallback.
{# templates/form-contact.html #}
<form method="{{ form.method }}" class="contact-form">
{{ form.csrf_field() }}
{% if form.form_error %}
<div class="alert">{{ form.form_error }}</div>
{% endif %}
<div class="row">
<div class="col">
{{ form['name'].label_tag() }}
{{ form['name'].widget(class_="form-input") }}
</div>
<div class="col">
{{ form['email'].label_tag() }}
{{ form['email'].widget(class_="form-input") }}
</div>
</div>
{{ form['message'].label_tag() }}
{{ form['message'].widget(class_="form-input", rows="8") }}
<button type="submit">{{ submit_label }}</button>
</form>
CSRF Flow
Form.__init__()— Createssecrets.token_urlsafe(32)in session if absent (key:_csrf_token)csrf_field()— Renders<input type="hidden" name="_csrf" value="{token}">validate()— Checks submitted_csrfagainst session token viahmac.compare_digest()- Token rotation — New token generated after successful check (single-use)
Registration Mechanism
Forms are registered in a global _form_registry dict (in model.py):
FormModel.__init_subclass__()auto-registers on class creation@form()decorator registers explicitlyget_form_model(name)retrieves by name, raisesLookupErrorif missing
Hook Integration
Two filter hooks fire after successful validation:
# Form-specific: e.g. "form_contact_validated"
self.data = await hooks.apply_filters(f"form_{self.name}_validated", self.data)
# Global: "form_validated"
self.data = await hooks.apply_filters("form_validated", self.data, self.name)
Example hook:
from skrift.hooks import filter
@filter("form_contact_validated")
async def sanitize_contact(data):
data.message = data.message.strip()
return data
@filter("form_validated")
async def log_all_forms(data, name):
print(f"Form '{name}' submitted")
return data
Jinja2 Global
The Form class is registered as a Jinja2 global, making it accessible in templates without passing it through context.
Key Files
| File | Purpose |
|------|---------|
| skrift/forms/core.py | Form — CSRF, validation, rendering |
| skrift/forms/model.py | FormModel base class, _form_registry, get_form_model() |
| skrift/forms/fields.py | BoundField — field bound to form instance |
| skrift/forms/decorators.py | @form() decorator |
| skrift/templates/form.html | Default form template |
From the file to a first result
The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.
View the source and supporting filesThis download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.
1. Download the file
Download SKILL.mdFrom the root of a test project, save the file as .skill-downloads/skrift-form-system-msy76ary/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.
Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.
mkdir -p '.skill-downloads/skrift-form-system-msy76ary' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/skrift-form-system-msy76ary/download' --output '.skill-downloads/skrift-form-system-msy76ary/SKILL.md.part' && mv '.skill-downloads/skrift-form-system-msy76ary/SKILL.md.part' '.skill-downloads/skrift-form-system-msy76ary/SKILL.md'2. Check prerequisites
Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.
No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.
The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.
3. Load the skill
After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.
Claude Code
test -f '.skill-downloads/skrift-form-system-msy76ary/SKILL.md' && test -s '.skill-downloads/skrift-form-system-msy76ary/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/skrift-forms' && cp -R '.skill-downloads/skrift-form-system-msy76ary' '.claude/skills/skrift-forms'Cursor
test -f '.skill-downloads/skrift-form-system-msy76ary/SKILL.md' && test -s '.skill-downloads/skrift-form-system-msy76ary/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/skrift-forms' && cp -R '.skill-downloads/skrift-form-system-msy76ary' '.cursor/skills/skrift-forms'Codex
test -f '.skill-downloads/skrift-form-system-msy76ary/SKILL.md' && test -s '.skill-downloads/skrift-form-system-msy76ary/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/skrift-forms' && cp -R '.skill-downloads/skrift-form-system-msy76ary' '.agents/skills/skrift-forms'OpenSkills
OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.
Official OpenSkills installationopenskills install './.skill-downloads/skrift-form-system-msy76ary'openskills read 'skrift-form-system-msy76ary'Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.
For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.
openskills syncManual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.
4. Try a first task
Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:
Read .skill-downloads/skrift-form-system-msy76ary/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.
React Hook Form Best Practices
Development
Master React Hook Form: avoid anti-patterns, manage subscriptions, and handle reset, dirty state, and controlled inputs correctly.
Emotion to Mantine Migration
Development
Migrate Emotion styled-components to Mantine components with style props and CSS modules. Use when converting .styled.tsx files or removing @emotion imports.
Scope Creep Detector
Development
Analyzes git diffs against a stated intent to detect scope creep, unrelated files, broad PRs, and oversized changes, then suggests keep, split, or justify actions.