diff --git a/swh/model/identifiers.py b/swh/model/identifiers.py
index e59a973e2bc479c09d71f8c0114af744f1d062b8..6a15c9be148c8209fd63023a971627f0489ae763 100644
--- a/swh/model/identifiers.py
+++ b/swh/model/identifiers.py
@@ -609,6 +609,12 @@ def persistent_identifier(type, object, version=1):
                                  identifier
         version (int): persistent identifier version (default to 1)
 
+    Raises:
+        ValidationError (class) in case of:
+
+            invalid type
+            invalid hash object
+
     Returns:
         Persistent identifier as string.
 
@@ -635,11 +641,16 @@ def persistent_identifier(type, object, version=1):
             'key_id': 'sha1_git'
         },
     }
-    o = _map[type]
+    o = _map.get(type)
+    if not o:
+        raise ValidationError('Wrong input: Supported types are %s' % (
+            list(_map.keys())))
+
     if isinstance(object, dict):  # internal swh representation resolution
         _hash = object[o['key_id']]
     else:  # client passed direct identifier (bytes/str)
         _hash = object
+    validate_sha1(_hash)  # can raise if invalid hash
     _hash = hash_to_hex(_hash)
     return 'swh:%s:%s:%s' % (version, o['short_name'], _hash)
 
diff --git a/swh/model/tests/test_identifiers.py b/swh/model/tests/test_identifiers.py
index ed36e1b2840cf676ec2749fd9217157590013757..7b0720e97f8f28795664b466ff992f42cbf12496 100644
--- a/swh/model/tests/test_identifiers.py
+++ b/swh/model/tests/test_identifiers.py
@@ -11,6 +11,7 @@ from nose.tools import istest
 
 from swh.model import hashutil, identifiers
 
+from swh.model.exceptions import ValidationError
 from swh.model.identifiers import SNAPSHOT, RELEASE, REVISION, DIRECTORY
 from swh.model.identifiers import CONTENT
 
@@ -816,6 +817,18 @@ class SnapshotIdentifier(unittest.TestCase):
 
             self.assertEquals(actual_value, expected_persistent_id)
 
+    def test_persistent_identifier_wrong_input(self):
+        _snapshot_id = 'notahash4bc0bf3d81436bf980b46e98bd338453'
+        _snapshot = {'id': _snapshot_id}
+
+        for _type, _hash, _error in [
+                (SNAPSHOT, _snapshot_id, 'Unexpected characters'),
+                (SNAPSHOT, _snapshot, 'Unexpected characters'),
+                ('foo', '', 'Wrong input: Supported types are'),
+        ]:
+            with self.assertRaisesRegex(ValidationError, _error):
+                identifiers.persistent_identifier(_type, _hash)
+
     def test_parse_persistent_identifier(self):
         for pid, _type, _version, _hash in [
                 ('swh:1:cnt:94a9ed024d3859793618152ea559a168bbcbb5e2', 'cnt',