try: score_batch(tf.constant([[1.0, 2.0]], dtype=tf.float32)) except TypeError as error: rejected_shape = type(error).__name__ else: rejected_shape = "not rejected"