Due to the diversity of implementations, many CSL files go beyond the CSL spec, β¦and some even go beyond the CSL-M extension.
Therefore, it would be quite helpful if we provide better error messages for malformed CSL files, for both end authors and developers.
- ~~Show the place of the error in the CSL file~~ (Edit on 2026-06-10: Thanks to https://github.com/typst/citationberg/pull/23, this is no longer a problem.)
- Show what data did not match any variant of the [untagged enum](https://serde.rs/enum-representations.html#untagged)
- Indicate whether the CSL file is really invalid or hayagriva does not support the feature yet
- (Optional) Ignore minor errors (take them as warnings) and continue parsing
Relates to https://github.com/typst/citationberg/issues/22 and https://github.com/typst/citationberg/pull/23, but this issue covers more.
### Common errors
According to [the survery](https://typst-doc-cn.github.io/csl-sanitizer/), **222 of 302 (74%)** CSL files in https://github.com/zotero-chinese/styles/tree/435cf756bf8bfaa193be236e27a347560ee39f54/src are considered malformed by hayagriva 799cfdc.
The error messages are as the follows.
- **196 (86%) Γ data did not match any variant of untagged enum Term**
(probably caused by `space-et-al` #291)
- **8 (4%) Γ unknown variant `institution`, expected one of `name`, `et-al`, `label`, `substitute`**
(might relate to #112)
- 6 Γ data did not match any variant of **untagged enum** Variable
- 4 Γ data did not match any variant of **untagged enum** TextTarget
- 4 Γ missing field `$value`
- 2 Γ unknown variant `monograph`, expected one of `article`, `article-journal`, `article-magazine`, `article-newspaper`, `bill`, `book`, `broadcast`, `chapter`, `classic`, `collection`, `dataset`, `document`, `entry`, `entry-dictionary`, `entry-encyclopedia`, `event`, `figure`, `graphic`, `hearing`, `interview`, `legal_case`, `legislation`, `manuscript`, `map`, `motion_picture`, `musical_score`, `pamphlet`, `paper-conference`, `patent`, `performance`, `periodical`, `personal_communication`, `post`, `post-weblog`, `regulation`, `report`, `review`, `review-book`, `software`, `song`, `speech`, `standard`, `thesis`, `treaty`, `webpage`
- 1 Γ missing field `term`
- 1 Γ unknown variant `last`, expected `first` or `all`
> The _duplicate field `layout`_ error should be the most common one at present.
> It's caused by CSL-M and tracked by https://github.com/typst/citationberg/issues/5.
> However, there are recent efforts improving it (e.g., #126), so I exclude this error by keeping only the last `<layout>` for `<citation>` and `<bibliography>` in CSL files.
EDIT on 2025-12-22: I added a few minimal examples in https://github.com/typst-doc-cn/csl-sanitizer/tree/main/tests/normalize/ .
### Links
The following discussions (in Chinese) describe the discrepancies in the CSL world.
- https://github.com/zotero-chinese/styles/pull/518
- https://github.com/zotero-chinese/styles/discussions/439