diff --git a/modules/saml/www/sp/metadata.php b/modules/saml/www/sp/metadata.php
index abf6473a26f5eb53d394a4fda199a7603681ac5c..c2f7a3b92b4ef7e90643f2ca254790165c642035 100644
--- a/modules/saml/www/sp/metadata.php
+++ b/modules/saml/www/sp/metadata.php
@@ -138,9 +138,16 @@ if ($certInfo !== null && array_key_exists('certData', $certInfo)) {
     $certData = null;
 }
 
-$format = $spconfig->getString('NameIDPolicy', null);
+$format = $spconfig->getValue('NameIDPolicy', null);
 if ($format !== null) {
-    $metaArray20['NameIDFormat'] = $format;
+    if (is_array($format)) {
+        $metaArray20['NameIDFormat'] = SimpleSAML_Configuration::loadFromArray($format)->getString(
+            'Format',
+            \SAML2\Constants::NAMEID_TRANSIENT
+        );
+    } elseif (is_string($format)) {
+        $metaArray20['NameIDFormat'] = $format;
+    }
 }
 
 $name = $spconfig->getLocalizedString('name', null);