gohugoio/hugo · error
failed to detect format from content
Error message
failed to detect format from content
What it means
Thrown by transform.Remarshal when the input data string's format cannot be auto-detected by metadecoders (tpl/transform/remarshal.go:42-44). Remarshal converts between JSON/YAML/TOML; if the source content matches none of these the detector returns empty and the error is raised.
Solutions
- Ensure the input is valid JSON, YAML, or TOML (test by parsing it standalone first).
- Pass a map instead of a string so detection is skipped: {{ transform.Remarshal "yaml" (dict "a" 1) }}.
- Trim/clean the string before passing; remove stray characters.
Example fix
// before
{{ transform.Remarshal "yaml" .RawBody }}
// after
{{ transform.Remarshal "yaml" .Params.config }} Defensive patterns
Strategy: validation
Validate before calling
{{/* Validate input parses as JSON/YAML/TOML before Remarshal, or pass a dict */}}
{{ transform.Remarshal "yaml" (dict "a" 1) }} Prevention
- Feed front matter / config blocks, not raw content bodies.
- Pass a map to bypass format detection.
When it happens
Trigger: Calling {{ transform.Remarshal "yaml" .SomeString }} where .SomeString is malformed or is plain text, CSV, INI, or otherwise not JSON/YAML/TOML.
Common situations: Passing truncated or commented-out front matter; feeding markdown body instead of front matter; encoding the data with an unsupported dialect; whitespace-only or non-ASCII delimiter issues.
Related errors
- failed to detect target data serialization format
- first argument must be a map
- must provide at least one argument
- no Key set in Resource
- transform.Highlight: expects at most 3 arguments
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/45d135abf0b3eb20.
Report an issue: GitHub.
Appendix: source
Thrown at tpl/transform/remarshal.go:44
return "", err
}
if m, ok := data.(map[string]any); ok {
meta = m
} else {
from, err := cast.ToStringE(data)
if err != nil {
return "", err
}
from = strings.TrimSpace(from)
if from == "" {
return "", nil
}
fromFormat := metadecoders.Default.FormatFromContentString(from)
if fromFormat == "" {
return "", errors.New("failed to detect format from content")
}
meta, err = metadecoders.Default.UnmarshalToMap([]byte(from), fromFormat)
if err != nil {
return "", err
}
}
// Make it so 1.0 float64 prints as 1 etc.
applyMarshalTypes(meta)
var result bytes.Buffer
if err := parser.InterfaceToConfig(meta, mark, &result); err != nil {
return "", err
}
return result.String(), nil
}View on GitHub (pinned to 52c9bd7908)