diff --git a/pystencils/data_types.py b/pystencils/data_types.py
index ffdbd84a7c3a2b5ea1e9d3b96c29bb2b5f4fd455..3b2fe35dadbfb2a0577973ed2e32d0280d637aa6 100644
--- a/pystencils/data_types.py
+++ b/pystencils/data_types.py
@@ -405,8 +405,10 @@ def get_type_of_expression(expr,
     elif isinstance(expr, TypedSymbol):
         return expr.dtype
     elif isinstance(expr, sp.Symbol):
-        return symbol_type_dict[expr.name]
-        # raise ValueError("All symbols iside this expression have to be typed! ", str(expr))
+        if symbol_type_dict:
+            return symbol_type_dict[expr.name]
+        else:
+            raise ValueError("All symbols inside this expression have to be typed! ", str(expr))
     elif isinstance(expr, cast_func):
         return expr.args[1]
     elif isinstance(expr, (vec_any, vec_all)):