grade-form-field looks at your user's input and assesses if they provide the information you're asking for. Try it out on the examples below.
Dark launch is on: checks are still sent and counted, but nothing shows. Turn off
Want this checking on your own form?
Get StartedAdd the checker to your form
Given is your website’s domain name.
Who does what: A · Admin B · Your server C · Your page D · Test
A · Admin Register with the admin do this first
-
Make a key pair on your server. Keep
myapp.com.private.pemsecret, on your server only.openssl ecparam -name prime256v1 -genkey -noout | openssl pkcs8 -topk8 -nocrypt -out myapp.com.private.pem openssl ec -in myapp.com.private.pem -pubout -out myapp.com.public.pem -
Paste the content of
myapp.com.public.pemhere (the public key is safe to share; never paste the private key):Send this message to the site admin:
The admin can take some days. Do B and C while you wait.
B · Your server Your server (backend)
-
For each page view, make a
gradeTokenon your server with this code. Give it each field’s name and expectation text, exactly as on the page (step 6). Pick your server's language. (Error handling is removed to make it short.)// makeGradeToken makes the gradeToken for one page view. // fields: field name -> its expectation text, exactly as on the page. func makeGradeToken(fields map[string]string) string { b, _ := os.ReadFile("myapp.com.private.pem") blk, _ := pem.Decode(b) key, _ := x509.ParsePKCS8PrivateKey(blk.Bytes) fp := map[string]string{} for name, expect := range fields { h := sha256.Sum256([]byte(strings.Join(strings.Fields(expect), " "))) fp[name] = "sha256:" + hex.EncodeToString(h[:]) } id := make([]byte, 12) rand.Read(id) now := time.Now().Unix() enc := func(v any) string { j, _ := json.Marshal(v); return base64.RawURLEncoding.EncodeToString(j) } data := enc(map[string]string{"alg": "ES256", "kid": "myapp.com"}) + "." + enc(map[string]any{ "iss": "myapp.com", "aud": "grade-form-field", "jti": hex.EncodeToString(id), "iat": now, "exp": now + 3600, "origin": "https://myapp.com", "max_checks": 50, "fields": fp, }) h := sha256.Sum256([]byte(data)) r, s, _ := ecdsa.Sign(rand.Reader, key.(*ecdsa.PrivateKey), h[:]) sig := make([]byte, 64) r.FillBytes(sig[:32]) s.FillBytes(sig[32:]) return data + "." + base64.RawURLEncoding.EncodeToString(sig) }import { createHash, randomBytes, sign } from "node:crypto"; import { readFileSync } from "node:fs"; // makeGradeToken makes the gradeToken for one page view. // fields: field name -> its expectation text, exactly as on the page. export function makeGradeToken(fields: Record<string, string>): string { const key = readFileSync("myapp.com.private.pem", "utf8"); const fp: Record<string, string> = {}; for (const [name, expect] of Object.entries(fields)) { const text = expect.trim().split(/\s+/).join(" "); fp[name] = "sha256:" + createHash("sha256").update(text).digest("hex"); } const now = Math.floor(Date.now() / 1000); const enc = (v: object) => Buffer.from(JSON.stringify(v)).toString("base64url"); const data = enc({ alg: "ES256", kid: "myapp.com" }) + "." + enc({ iss: "myapp.com", aud: "grade-form-field", jti: randomBytes(12).toString("hex"), iat: now, exp: now + 3600, origin: "https://myapp.com", max_checks: 50, fields: fp, }); const sig = sign("sha256", Buffer.from(data), { key, dsaEncoding: "ieee-p1363" }); return data + "." + sig.toString("base64url"); }# pip install cryptography import base64, hashlib, json, os, time from cryptography.hazmat.primitives import hashes, serialization from cryptography.hazmat.primitives.asymmetric import ec from cryptography.hazmat.primitives.asymmetric.utils import decode_dss_signature def make_grade_token(fields: dict[str, str]) -> str: """Make the gradeToken for one page view. fields: field name -> its expectation text, exactly as on the page.""" with open("myapp.com.private.pem", "rb") as f: key = serialization.load_pem_private_key(f.read(), password=None) fp = {name: "sha256:" + hashlib.sha256(" ".join(expect.split()).encode()).hexdigest() for name, expect in fields.items()} now = int(time.time()) enc = lambda v: base64.urlsafe_b64encode(json.dumps(v).encode()).rstrip(b"=").decode() data = enc({"alg": "ES256", "kid": "myapp.com"}) + "." + enc({ "iss": "myapp.com", "aud": "grade-form-field", "jti": os.urandom(12).hex(), "iat": now, "exp": now + 3600, "origin": "https://myapp.com", "max_checks": 50, "fields": fp, }) r, s = decode_dss_signature(key.sign(data.encode(), ec.ECDSA(hashes.SHA256()))) sig = r.to_bytes(32, "big") + s.to_bytes(32, "big") return data + "." + base64.urlsafe_b64encode(sig).rstrip(b"=").decode()require "base64" require "digest" require "json" require "openssl" require "securerandom" # make_grade_token makes the gradeToken for one page view. # fields: field name -> its expectation text, exactly as on the page. def make_grade_token(fields) key = OpenSSL::PKey.read(File.read("myapp.com.private.pem")) fp = fields.to_h { |name, expect| [name, "sha256:" + Digest::SHA256.hexdigest(expect.split.join(" "))] } now = Time.now.to_i enc = ->(v) { Base64.urlsafe_encode64(JSON.generate(v), padding: false) } data = enc.({ alg: "ES256", kid: "myapp.com" }) + "." + enc.({ iss: "myapp.com", aud: "grade-form-field", jti: SecureRandom.hex(12), iat: now, exp: now + 3600, origin: "https://myapp.com", max_checks: 50, fields: fp, }) der = key.sign(OpenSSL::Digest::SHA256.new, data) sig = OpenSSL::ASN1.decode(der).value.map { |i| i.value.to_s(2).rjust(32, "\x00") }.join data + "." + Base64.urlsafe_encode64(sig, padding: false) end -
Write it on
<body>in your page template:<body data-grade-form-field-token="gradeToken value goes here"> -
If your server sends a
Content-Security-Policyheader, addhttps://THIS-SITEtoscript-srcandconnect-src. If it does not, skip this step.
Keep in mind: put the token only on pages behind your own login, if you can. On a public page, anyone can get a token.
C · Your page Your page (frontend)
-
Mark the fields on your form, and add a box for each result. Without the box, no result shows.
<input type="file" data-grade-form-field-field="bank-statement" data-grade-form-field-expect="A PDF of your recent bank statement, showing ..." > <div data-grade-form-field-verdict-for="bank-statement" ></div> -
Add the script:
<script src="https://THIS-SITE/embed.js"></script>
Optional: change how the result looks
Styles: these are all our styles, each with body in front. Copy the lines you want to change into your own CSS, and change them. Your lines are then used instead of ours. grade-form-field-verdict (the sentence) has no style of its own.
body .grade-form-field-result { margin-top: 8px; font: 14px/1.45 system-ui, -apple-system, sans-serif; min-height: 1.4em; } /* the box */
body .grade-form-field-status { opacity: .7; } /* "Checking…" */
body .grade-form-field-spin { display: inline-block; width: .9em; height: .9em; border: 2px solid #8884; border-top-color: #3b5bdb; border-radius: 50%; animation: grade-form-field-s .8s linear infinite; vertical-align: -2px; margin-right: 6px; }
body .grade-form-field-result ul { margin: 4px 0 0; padding: 0; list-style: none; }
body .grade-form-field-result li { padding-left: 1.4em; position: relative; }
body .grade-form-field-result li::before { position: absolute; left: 0; font-weight: 700; }
body .grade-form-field-ok::before { content: "✓"; color: #1a7f4b; } /* what the answer has */
body .grade-form-field-no::before { content: "✗"; color: #b42318; } /* what it lacks */
body .grade-form-field-err { color: #b42318; } /* error text */
@media (prefers-color-scheme: dark) {
body .grade-form-field-ok::before { color: #4cc38a; }
body .grade-form-field-no::before, body .grade-form-field-err { color: #f97066; }
}
Your own result: put this after the script. It is called each time a field changes state. Return our element, your own element, or null to add nothing (then you can show the result in any place).
<script>
GradeFormField.processResult = function (field, resultJSON, resultNode) {
// field: the input element
// resultJSON: one of
// { state: "checking", field }
// { state: "graded", field, score, verdict, satisfied, missing }
// { state: "failed", field, code, message }
// { state: "cleared", field }
// resultNode: the element we made from it
return resultNode;
};
</script>
Optional: dark launch
Add data-grade-form-field-dark-launch="true" to <body>. Every check is still sent and counted, but nothing shows on your page. Use it to measure the load before your visitors see the checker. Try it here
D · Test Test
-
Open your page and type in a field. The result shows in its box. If the box shows “Could not check: …”, find the text here:
Text after “Could not check:” Cause Fix this website address is not registered
unknown key idThe admin has not added your website or key yet. A step 2 this page has no token No token on <body>.B step 4 signature does not match
token is not a JWTThe token is not made correctly, or with a different key. B step 3 field … is not in the token
expectation text … does not match the tokenThe fields in the token are not the same as on the page. B step 3, C step 6 Failed to fetch Your Content Security Policy blocks the checker. B step 5 No box changes at all? Check that the script is on the page (step 7), that each field has its box (step 6), and that dark launch is off.
Host grade-form-field on GCC AWS (ECS)
Your instance has three parts. The model runs on your own GPU server, so what people type and upload stays in your AWS account.
port 8080
port 11434, private
-
Give this to your devops team (or their agent). It has all they need to set up the services or write the Terraform.
Deploy grade-form-field on AWS ECS (GCC, ap-southeast-1). Two ECS services in one VPC. Order: 1. ollama, 2. pull the model, 3. app. The app does not start until the model is on the model server. 1. ollama (the model server, private) - Capacity: ECS on EC2, GPU instance g4dn.12xlarge (4x NVIDIA T4, 16 GB each), ECS GPU-optimized AMI (Amazon Linux 2023). The model needs about 30 GB of GPU memory; Ollama splits it across the 4 cards by itself (tested). g6e, g6, g5 and p5 are not offered in ap-southeast-1. About US$5.47/hour, US$4,000/month left on. Service quota "Running On-Demand G and VT instances": 48 vCPU per instance. - Image: ollama/ollama (mirror it into ECR if Docker Hub is blocked) - Container: port 11434, resourceRequirements GPU = 4 - Env: OLLAMA_HOST=0.0.0.0, OLLAMA_KEEP_ALIVE=-1 (keep the model loaded) - Model files: mount EFS at /root/.ollama, then pull once: ollama pull qwen3.8:27b-mtp-q8_0 (about 30 GB, about 2 minutes) - Warm-up: the first check after ollama starts loads the model into the GPUs (about 1.5 minutes). To do this before people use it: curl http://<ollama address>:11434/api/generate \ -d '{"model":"qwen3.8:27b-mtp-q8_0","keep_alive":-1}' - Health check: GET / returns "Ollama is running" - Reachable only from the app (internal ALB or ECS Service Connect). Never public. - Scale: 1 task per GPU instance. More tasks = more checks at a time. 2. app (grade-form-field, public) - Capacity: Fargate, 0.5 vCPU / 1 GB, 2 tasks - Image: registry.sgts.gitlab-dedicated.com/wog/sub/judiciary-cicd/jud-fcms/grade-form-field:<short commit> (GitLab project wog/sub/judiciary-cicd/jud-fcms/grade-form-field, built by its pipeline from Dockerfile.ci; linux/amd64, so Fargate X86_64). Copy it into ECR if ECS cannot pull from GitLab. Port 8080. - Start: the app checks once that the model server has MODEL. If not, it stops ("has no model ... pull it first"), and ECS restarts it with longer and longer waits. After you pull the model, force a new deployment. - Health check: GET /health returns "ok" - Public ALB with HTTPS (ACM certificate) -> target group port 8080. HTTPS is required: browsers block an http script on an https page. Idle timeout 180 s (the first check after a start takes about 1.5 minutes). Uploads up to 15 MB. - Env: OLLAMA_URL=http://<ollama address>:11434 MODEL=qwen3.8:27b-mtp-q8_0 TRUST_PROXY=true SITES_JSON=<websites allowed to embed the checker; see "Register a website"> - Secret (task definition "secrets", from Secrets Manager): HOMEPAGE_SIGNING_KEY = an ES256 (P-256) private key, PEM. Make it once: openssl ecparam -name prime256v1 -genkey -noout | openssl pkcs8 -topk8 -nocrypt All tasks must use the same key. Without it, the app does not start. - SITES_JSON is read at start: to change it, deploy again. - Limits (per_minute, per_day, ...) are counted in each task's memory, so with N tasks they are about N times looser. 3. IAM for whoever creates this - Creating the ALB also needs ec2:GetSecurityGroupsForVpc. - ecs:DeregisterTaskDefinition works only with Resource "*". Done when: the homepage opens over HTTPS, and "Try a sample" in the Demo tab shows a score (the first check after a start can take about 1.5 minutes; then about 8 s for a text PDF, 15–23 s for a scanned one). -
Model server: Ollama + Qwen. The model is about 30 GB. In Singapore, use
g4dn.12xlarge(4 × 16 GB T4); Ollama splits the model across the 4 GPUs by itself. Ask for the GPU quota first (“Running On-Demand G and VT instances”, 48 per instance); approval can take a day or two.{ "name": "ollama", "image": "<ECR mirror of ollama/ollama>", "portMappings": [{ "containerPort": 11434 }], "resourceRequirements": [{ "type": "GPU", "value": "4" }], "environment": [ { "name": "OLLAMA_HOST", "value": "0.0.0.0" }, { "name": "OLLAMA_KEEP_ALIVE", "value": "-1" } ], "mountPoints": [{ "sourceVolume": "models", "containerPath": "/root/.ollama" }] }Put the model on the EFS volume once (about 2 minutes), before you start the app:
ollama pull qwen3.8:27b-mtp-q8_0 -
The app. Make the homepage's signing key once, and keep it in Secrets Manager. All tasks use the same key. If
HOMEPAGE_SIGNING_KEYis not set, or the model is not pulled yet, the app does not start. After you pull the model, force a new deployment.openssl ecparam -name prime256v1 -genkey -noout | openssl pkcs8 -topk8 -nocrypt -out homepage.private.pem{ "name": "app", "image": "registry.sgts.gitlab-dedicated.com/wog/sub/judiciary-cicd/jud-fcms/grade-form-field:<short commit>", "portMappings": [{ "containerPort": 8080 }], "environment": [ { "name": "OLLAMA_URL", "value": "http://<ollama address>:11434" }, { "name": "MODEL", "value": "qwen3.8:27b-mtp-q8_0" }, { "name": "TRUST_PROXY", "value": "true" }, { "name": "SITES_JSON", "value": "<see 4. Register a website>" } ], "secrets": [ { "name": "HOMEPAGE_SIGNING_KEY", "valueFrom": "<Secrets Manager ARN>" } ] } -
Register a website (
SITES_JSON). A website's developer sends you a JSON entry with its public key and the address of its form pages. Save it asentry.jsonand add it tosites.json:jq -s '.[0] + .[1]' sites.json entry.json > sites.json.new && mv sites.json.new sites.jsonPut the file's content in
SITES_JSONand deploy again. The app reads it only at start.Limits are optional:
per_minute,per_day,per_ip_per_minute,max_checks,max_ttl_seconds. Seeaws/sites/sites.example.json. -
Scaling. The GPU is the limit, not the app. For more checks at a time, add Ollama tasks (one GPU instance each). Two app tasks are enough.
Limits are per task: each app task counts in its own memory. With N tasks, the limits are about N times looser.
-
When a website changes its key: add the new public key next to the old one, under the new key id (e.g.
myapp.com-2), and deploy. When the website has switched, remove the old key and deploy again.
The last checks on this server. In each chart the newest is on the right, and the big number is the latest value. Checks and problems are per hour over the last 24 hours; the other charts show the last 50 checks. Pick a field to see only its checks; the numbers are its checks in the last 24 hours. What people typed or uploaded is never kept.