dgraph-io/dgraph · error
NQuad failed sanity check. Subject
Error message
NQuad failed sanity check. Subject: %q, Predicate: %q, ObjectId: %q
What it means
ParseRDF validates each parsed NQuad before returning it. If the subject, predicate, or object ID contains characters that the sane() check rejects (control/whitespace/special characters), the NQuad cannot be safely indexed and the parse fails. The full input line is deliberately omitted from the message because RDF lines may contain sensitive data.
Solutions
- Inspect the Subject/Predicate/ObjectId values quoted in the error and remove or escape invalid characters (spaces, control chars).
- Ensure IRIs are wrapped in angle brackets <...> and blank nodes use the _:name form in the input line.
- Pre-validate NQuads with the sane() check (or api.ValidateNQuad) before feeding lines to ParseRDF.
- If the line is machine-generated, fix the upstream generator to emit canonical N-Quads.
Example fix
// before
ParseRDF("<http://ex/s> has name Alice .") // invalid predicate 'has name'
// after
ParseRDF("<http://ex/s> <http://ex/name> \"Alice\" .") // bracketed predicate, literal object Defensive patterns
Strategy: validation
Validate before calling
func validNQuadLine(line string) bool {
for _, part := range []string{subject, predicate, objectId} {
if !sane(part) { return false }
}
return true
} Type guard
func isSane(s string) bool { return sane(s) } Try / catch
rnq, err := ParseRDF(line)
if err != nil {
if strings.Contains(err.Error(), "failed sanity check") {
log.Warn("skipping invalid NQuad", "err", err)
return nil // skip or quarantine line
}
return err
} Prevention
- Run sane()/api validation on NQuads before serializing them into .nq files.
- Always bracket IRIs in <> and prefix blank nodes with _:.
- Strip control characters and trim whitespace from identifiers at generation time.
- Lint RDF dumps with an N-Quads validator before import.
When it happens
Trigger: Calling ParseRDF (or Parse/ParseRDFs) with an N-Quads line whose subject, predicate, or object ID contains invalid characters such as spaces, control characters, or unescaped special chars. Also occurs when a subject lacks a valid <...> or _:name form.
Common situations: Importing RDF dumps exported from other triple stores with loosely validated identifiers; hand-written .nq files with typos like unbracketed IRIs or stray whitespace; programmatic NQuad construction that skips validation before serialization.
Related errors
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/d6b3cea7820846d9.
Report an issue: GitHub.
Appendix: source
Thrown at chunker/rdf_parser.go:225
return rnq, fmt.Errorf("invalid end of input. Input: [%s]", line)
}
if isCommentLine {
return rnq, ErrEmpty
}
// We only want to set default value if we have seen ObjectValue within "" and if we didn't
// already set it.
if seenOval && rnq.ObjectValue == nil {
rnq.ObjectValue = &api.Value{Val: &api.Value_DefaultVal{DefaultVal: oval}}
}
if len(rnq.Subject) == 0 || len(rnq.Predicate) == 0 {
return rnq, fmt.Errorf("empty required fields in NQuad. Input: [%s]", line)
}
if len(rnq.ObjectId) == 0 && rnq.ObjectValue == nil {
return rnq, fmt.Errorf("no Object in NQuad. Input: [%s]", line)
}
if !sane(rnq.Subject) || !sane(rnq.Predicate) || !sane(rnq.ObjectId) {
// Don't format the full line, as it may contain sensitive information
return rnq, fmt.Errorf("NQuad failed sanity check. Subject: %q, Predicate: %q, ObjectId: %q",
rnq.Subject, rnq.Predicate, rnq.ObjectId)
}
return rnq, nil
}
// parseFunction parses uid(<var name>) and returns
// uid(<var name>) after striping whitespace if any
func parseFunction(it *lex.ItemIterator) (string, error) {
item := it.Item()
s := item.Val
it.Next()
if item = it.Item(); item.Typ != itemLeftRound {
return "", fmt.Errorf("expected '(', found: %s", item.Val)
}
it.Next()View on GitHub (pinned to 759e242be6)