{"record":{"id":"d6b3cea7820846d9","repo":"dgraph-io/dgraph","slug":"nquad-failed-sanity-check-subject-q-predicate","errorCode":null,"errorMessage":"NQuad failed sanity check. Subject: %q, Predicate: %q, ObjectId: %q","messagePattern":"NQuad failed sanity check\\. Subject: %q, Predicate: %q, ObjectId: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"chunker/rdf_parser.go","lineNumber":225,"sourceCode":"\t\treturn rnq, fmt.Errorf(\"invalid end of input. Input: [%s]\", line)\n\t}\n\tif isCommentLine {\n\t\treturn rnq, ErrEmpty\n\t}\n\t// We only want to set default value if we have seen ObjectValue within \"\" and if we didn't\n\t// already set it.\n\tif seenOval && rnq.ObjectValue == nil {\n\t\trnq.ObjectValue = &api.Value{Val: &api.Value_DefaultVal{DefaultVal: oval}}\n\t}\n\tif len(rnq.Subject) == 0 || len(rnq.Predicate) == 0 {\n\t\treturn rnq, fmt.Errorf(\"empty required fields in NQuad. Input: [%s]\", line)\n\t}\n\tif len(rnq.ObjectId) == 0 && rnq.ObjectValue == nil {\n\t\treturn rnq, fmt.Errorf(\"no Object in NQuad. Input: [%s]\", line)\n\t}\n\tif !sane(rnq.Subject) || !sane(rnq.Predicate) || !sane(rnq.ObjectId) {\n\t\t// Don't format the full line, as it may contain sensitive information\n\t\treturn rnq, fmt.Errorf(\"NQuad failed sanity check. Subject: %q, Predicate: %q, ObjectId: %q\",\n\t\t\trnq.Subject, rnq.Predicate, rnq.ObjectId)\n\t}\n\n\treturn rnq, nil\n}\n\n// parseFunction parses uid(<var name>) and returns\n// uid(<var name>) after striping whitespace if any\nfunc parseFunction(it *lex.ItemIterator) (string, error) {\n\titem := it.Item()\n\ts := item.Val\n\n\tit.Next()\n\tif item = it.Item(); item.Typ != itemLeftRound {\n\t\treturn \"\", fmt.Errorf(\"expected '(', found: %s\", item.Val)\n\t}\n\n\tit.Next()","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/chunker/rdf_parser.go#L207-L243","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nParseRDF(\"<http://ex/s> has name Alice .\")            // invalid predicate 'has name'\n// after\nParseRDF(\"<http://ex/s> <http://ex/name> \\\"Alice\\\" .\")  // bracketed predicate, literal object","handlingStrategy":"validation","validationCode":"func validNQuadLine(line string) bool {\n\tfor _, part := range []string{subject, predicate, objectId} {\n\t\tif !sane(part) { return false }\n\t}\n\treturn true\n}","typeGuard":"func isSane(s string) bool { return sane(s) }","tryCatchPattern":"rnq, err := ParseRDF(line)\nif err != nil {\n\tif strings.Contains(err.Error(), \"failed sanity check\") {\n\t\tlog.Warn(\"skipping invalid NQuad\", \"err\", err)\n\t\treturn nil // skip or quarantine line\n\t}\n\treturn err\n}","preventionTips":["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."],"tags":["rdf","parsing","validation","dgraph"],"backgroundTag":"rdf-nquad-validation-failed","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}