# Backend API to validate card template / field names before saving

**URL:** <https://forums.ankiweb.net/t/backend-api-to-validate-card-template-field-names-before-saving/74551>\
**Category:** Development\
**Created:** [November 16, 2026, 8:51pm UTC](https://forums.ankiweb.net/t/backend-api-to-validate-card-template-field-names-before-saving/74551 "2026-11-16T20:51:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Capthunder19](https://avatars.discourse-cdn.com/v4/letter/c/c68b51/32.png) [@Capthunder19](https://forums.ankiweb.net/u/Capthunder19)\
**Post date:** [November 16, 2026, 8:51pm UTC](https://forums.ankiweb.net/t/backend-api-to-validate-card-template-field-names-before-saving/74551/1 "2026-11-16T20:51:48Z")

</div>

I contribute to AnkiDroid. While fixing card-type rename bugs, we keep  
finding small edge cases where AnkiDroid’s own name checks don’t match  
what the backend does on save. Rather than keep patching the client, the  
AnkiDroid maintainers suggested asking whether these checks could live in  
the backend:

> <https://github.com/ankidroid/Anki-Android/issues/22298>
>
> \### Checked for duplicates?
> 
> \- \[x\] This issue is not a duplicate
> 
> \### Does it al…so happen in the desktop version?
> 
> \- \[x\] This bug does not occur in the latest version of Anki Desktop
> 
> \### What are the steps to reproduce this bug?
> 
> 1. Manage note types → + → Clone: Basic (and reversed card)
> 2. Edit cards → Card 2 tab → ⋮ → Rename card type
> 3. Type "Card 1" including the double quotes. Rename stays enabled.
> 4. Tap Rename, then ✓ to save
> 5. Reopen Edit cards: the card type is now named "Card 1+"
> 
> The dialog compares names with the quotes included, but the backend strips " when saving. The name then becomes a duplicate, so the backend appends "+".
> 
> 
> \### Expected behaviour
> 
> Rename should be disabled with "Name already exists", because the name is a duplicate once the quotes are removed. Anki Desktop strips " from the new name before using it
> 
> 
> \### Debug info
> 
> \`\`\`text
> AnkiDroid Version = 2.24.0 (ebcf8e0e34921628b9b8a496c66ffd4adbb3705f)  
> Backend Version = 0.1.64-anki25.09.2 (25.09.2 3890e12c9e48c028c3f12aa58cb64bd9f8895e30)  
> Android Version = 15 (SDK 35)  
> ProductFlavor = play  
> Device Info = OPPO | OPPO | OP574FL1 | CPH2577 | CPH2577 | mt6768  
> WebView Info = \[com.google.android.webview | 801003603\]: Mozilla/5.0 (Linux; Android 15; CPH2577 Build/AP3A.240617.008; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/153.0.8010.36 Mobile Safari/537.36  
> ACRA UUID = e76ebe42-1f6f-4830-ac63-426b439fda94  
> FSRS = 5.1.0 (Enabled: false)  
> Crash Reports Enabled = true
> \`\`\`
> 
> \### (Optional) Anything else you want to share?
> 
> Follow-up from #22117 (suggested by @criticalAY). Tested on AnkiDroid 2.24.0.
> 
> 
> \### Research
> 
> \- \[x\] I have checked the \[manual\](https://docs.ankidroid.org/) and the \[FAQ\](https://github.com/ankidroid/Anki-Android/wiki/FAQ) and could not find a solution to my issue
> \- \[\] (Optional) I have confirmed the issue is not resolved in the latest alpha release (\[instructions\](https://docs.ankidroid.org/manual.html#betaTesting))

**Is your feature request related to a problem? Please describe.**

When a notetype is saved, `Notetype::prepare_for_update` normalizes names:

- NFC-normalizes all names
- `CardTemplate::fix_name` strips `"`; rejects empty or quote-only names
- `NoteField::fix_name` strips `: { } "`, trims, and strips leading `# / ^`
- `ensure_names_unique` appends `+` to case-insensitive duplicates

No API exposes these rules without saving, so a client that wants to show  
“Name already exists” has to copy them, and the copies drift. Example:  
in AnkiDroid, renaming Card 2 to `"Card 1"` (with quotes) gets past the  
client-side duplicate check, and the backend then saves it as `Card 1+`.

This rarely affects real users. The concern is that every client-side  
patch adds code that can drift again.

Anki Desktop’s rename dialog doesn’t check for duplicates either, so a  
duplicate name there is also saved with `+` and no warning.

**Describe the solution you’d like**

A read-only RPC in NotetypesService that runs the existing checks and  
returns the result without saving. For example:

```auto
rpc CheckNotetypeNames(Notetype) returns (CheckNotetypeNamesResponse);

```

It would return the normalized names and any problems (duplicate, empty,  
quotes only). The save path could call the same function, so the two can’t  
get out of step.

Drawback: one more RPC to maintain. It could start as an unstable API if  
you’d rather not commit to it yet.

**Describe alternatives you’ve considered**

1. Keep the checks in each client. This is what AnkiDroid does now, and  
it keeps drifting.
2. Smaller per-name helpers, for example  
`NormalizeCardTemplateName(String) -> String`, with the client still  
comparing for duplicates.
3. Do nothing. That’s reasonable given the low impact, but then clients  
will keep patching around these cases.

Is this something you’d accept? If so, which shape do you prefer, and  
should it be unstable or official? I’m happy to write the PR
