diff --git a/meta/classes-recipe/go-mod-update-modules.bbclass b/meta/classes-recipe/go-mod-update-modules.bbclass
index bcb80e130d..030099fb0f 100644
--- a/meta/classes-recipe/go-mod-update-modules.bbclass
+++ b/meta/classes-recipe/go-mod-update-modules.bbclass
@@ -19,6 +19,10 @@ do_update_modules[network] = "1"
 GO_MOD_LICENSE_SCANNER ??= ""
 do_update_modules[depends] += "${@'licensecheck-native:do_populate_sysroot' if d.getVar('GO_MOD_LICENSE_SCANNER') == 'licensecheck' else ''}"
 
+# Set to "1" to fail, without writing the files, when the license of a file is
+# not identified. The error lists the hashes to add to a license-hashes.csv.
+GO_MOD_LICENSE_STRICT ??= "0"
+
 python do_update_modules() {
     import subprocess, tempfile, json, re, urllib.parse
     from oe.license_finder import find_licenses_up
@@ -120,6 +124,15 @@ python do_update_modules() {
                     bb.note(f"{lic_file}: no license beyond {' '.join(sorted(declared))}, left out")
                     del lic_files[lic_file]
 
+        unknown = [(f, md5) for f, (node, md5) in lic_files.items()
+                   if isinstance(node, oe.spdx_license.UnknownId)]
+        if unknown and bb.utils.to_boolean(d.getVar("GO_MOD_LICENSE_STRICT")):
+            bb.fatal("Licenses not identified, %s-licenses.inc not written:\n%s\n"
+                     "Once each license is verified, add md5,SPDX lines like these to a "
+                     "files/license-hashes.csv in a layer:\n%s" % (
+                         bpn, "\n".join(f"  {f}" for f, _ in unknown),
+                         "\n".join(sorted({f"  {md5},Unknown" for _, md5 in unknown}))))
+
         licenses = []
         lic_files_chksum = []
         for lic_file in lic_files:
