diff --git a/sosw/components/dynamo_db.py b/sosw/components/dynamo_db.py
index ba52847..d7686c6 100644
--- a/sosw/components/dynamo_db.py
+++ b/sosw/components/dynamo_db.py
@@ -261,6 +261,11 @@ class DynamoDbClient:
                 if val_dict:
                     val = val_dict.get(key_type)  # Ex: 1234 or "myvalue"
 
+                    if val is None and key_type not in val_dict:
+                        real_type = list(val_dict.keys())[0]
+                        raise ValueError(f"'{key}' is expected to be of type '{key_type}' in row_mapper, "
+                                         f"but real value is of type '{real_type}'")
+
                     # type_deserializer.deserialize() parses 'N' to `Decimal` type but it cant be parsed to a datetime
                     # so we cast it to either an integer or a float.
                     if key_type == 'N':

DynamoDB - exception on wrong type in row_mapper
When row_mapper type is of one type (for example 'S'), and real type from DB is of another type (for example 'N')
This exception happens:

<img width="834" alt="Screen Shot 2020-07-08 at 13 59 53" src="https://user-images.githubusercontent.com/11838450/86911422-f7956280-c123-11ea-83cf-d9f207ed3c1c.png">

Options (choose one)
1. Raise informative exception
2. Convert to the expected type if possible

I prefer the 1st option.
diff --git a/sosw/components/test/unit/test_dynamo_db.py b/sosw/components/test/unit/test_dynamo_db.py
index 30dace2..e9022ee 100644
--- a/sosw/components/test/unit/test_dynamo_db.py
+++ b/sosw/components/test/unit/test_dynamo_db.py
@@ -201,6 +201,21 @@ class dynamodb_client_UnitTestCase(unittest.TestCase):
         self.assertDictEqual(res, expected)
 
 
+    def test_dynamo_to_dict__mapping_doesnt_match__raises(self):
+        # If the value type in the DB doesn't match the expected type in row_mapper - raise ValueError
+
+        dynamo_row = {
+            'hash_col':   {'S': 'aaa'}, 'range_col': {'N': '123'},
+            'other_col': {'N': '111'}  # In the row_mapper, other_col is of type 'S'
+        }
+
+        with self.assertRaises(ValueError) as e:
+            dict_row = self.dynamo_client.dynamo_to_dict(dynamo_row)
+
+        self.assertEqual("'other_col' is expected to be of type 'S' in row_mapper, but real value is of type 'N'",
+                         str(e.exception))
+
+
     def test_get_by_query__validates_comparison(self):
         self.assertRaises(AssertionError, self.dynamo_client.get_by_query, keys={'k': '1'},
                           comparisons={'k': 'unsupported'})

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest sphinx sphinx_rtd_theme sphinx_sitemap
apt-get update apt-get install -y gcc
3.9
requirements/base.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
alabaster==0.7.16
babel==2.17.0
boto3==1.37.23
botocore==1.37.23
certifi==2025.1.31
charset-normalizer==3.4.1
docutils==0.21.2
exceptiongroup==1.2.2
idna==3.10
imagesize==1.4.1
importlib_metadata==8.6.1
iniconfig==2.1.0
Jinja2==3.1.6
jmespath==1.0.1
MarkupSafe==3.0.2
packaging==24.2
pluggy==1.5.0
Pygments==2.19.1
pytest==8.3.5
python-dateutil==2.9.0.post0
requests==2.32.3
s3transfer==0.11.4
six==1.17.0
snowballstemmer==2.2.0
-e git+https://github.com/sosw/sosw.git@e1e4b9c3fdc321830f6eb3f04c4f40b08c23238a#egg=sosw
Sphinx==7.4.7
sphinx-rtd-theme==3.0.2
sphinx-sitemap==2.6.0
sphinxcontrib-applehelp==2.0.0
sphinxcontrib-devhelp==2.0.0
sphinxcontrib-htmlhelp==2.1.0
sphinxcontrib-jquery==4.1
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==2.0.0
sphinxcontrib-serializinghtml==2.0.0
tomli==2.2.1
urllib3==1.26.20
zipp==3.21.0

name: sosw
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - alabaster==0.7.16
      - babel==2.17.0
      - boto3==1.37.23
      - botocore==1.37.23
      - certifi==2025.1.31
      - charset-normalizer==3.4.1
      - docutils==0.21.2
      - exceptiongroup==1.2.2
      - idna==3.10
      - imagesize==1.4.1
      - importlib-metadata==8.6.1
      - iniconfig==2.1.0
      - jinja2==3.1.6
      - jmespath==1.0.1
      - markupsafe==3.0.2
      - packaging==24.2
      - pluggy==1.5.0
      - pygments==2.19.1
      - pytest==8.3.5
      - python-dateutil==2.9.0.post0
      - requests==2.32.3
      - s3transfer==0.11.4
      - six==1.17.0
      - snowballstemmer==2.2.0
      - sphinx==7.4.7
      - sphinx-rtd-theme==3.0.2
      - sphinx-sitemap==2.6.0
      - sphinxcontrib-applehelp==2.0.0
      - sphinxcontrib-devhelp==2.0.0
      - sphinxcontrib-htmlhelp==2.1.0
      - sphinxcontrib-jquery==4.1
      - sphinxcontrib-jsmath==1.0.1
      - sphinxcontrib-qthelp==2.0.0
      - sphinxcontrib-serializinghtml==2.0.0
      - tomli==2.2.1
      - urllib3==1.26.20
      - zipp==3.21.0
prefix: /opt/conda/envs/sosw

sosw/components/test/unit/test_dynamo_db.py::dynamodb_client_UnitTestCase::test_dynamo_to_dict__mapping_doesnt_match__raises
sosw/components/test/unit/test_dynamo_db.py::dynamodb_client_UnitTestCase::test__parse_filter_expression sosw/components/test/unit/test_dynamo_db.py::dynamodb_client_UnitTestCase::test__parse_filter_expression__raises sosw/components/test/unit/test_dynamo_db.py::dynamodb_client_UnitTestCase::test_batch_get_items_one_table__not_strict sosw/components/test/unit/test_dynamo_db.py::dynamodb_client_UnitTestCase::test_batch_get_items_one_table__strict sosw/components/test/unit/test_dynamo_db.py::dynamodb_client_UnitTestCase::test_create__calls_boto_client sosw/components/test/unit/test_dynamo_db.py::dynamodb_client_UnitTestCase::test_create__calls_put sosw/components/test/unit/test_dynamo_db.py::dynamodb_client_UnitTestCase::test_create__raises__if_no_hash_col_configured sosw/components/test/unit/test_dynamo_db.py::dynamodb_client_UnitTestCase::test_dict_to_dynamo__not_strict__map_type sosw/components/test/unit/test_dynamo_db.py::dynamodb_client_UnitTestCase::test_dict_to_dynamo_not_strict sosw/components/test/unit/test_dynamo_db.py::dynamodb_client_UnitTestCase::test_dict_to_dynamo_prefix sosw/components/test/unit/test_dynamo_db.py::dynamodb_client_UnitTestCase::test_dict_to_dynamo_strict sosw/components/test/unit/test_dynamo_db.py::dynamodb_client_UnitTestCase::test_dynamo_to_dict sosw/components/test/unit/test_dynamo_db.py::dynamodb_client_UnitTestCase::test_dynamo_to_dict__do_json_loads sosw/components/test/unit/test_dynamo_db.py::dynamodb_client_UnitTestCase::test_dynamo_to_dict__dont_json_loads sosw/components/test/unit/test_dynamo_db.py::dynamodb_client_UnitTestCase::test_dynamo_to_dict_no_strict_row_mapper sosw/components/test/unit/test_dynamo_db.py::dynamodb_client_UnitTestCase::test_get_by_query__between sosw/components/test/unit/test_dynamo_db.py::dynamodb_client_UnitTestCase::test_get_by_query__expr_attr sosw/components/test/unit/test_dynamo_db.py::dynamodb_client_UnitTestCase::test_get_by_query__max_items_and_count__raises sosw/components/test/unit/test_dynamo_db.py::dynamodb_client_UnitTestCase::test_get_by_query__return_count sosw/components/test/unit/test_dynamo_db.py::dynamodb_client_UnitTestCase::test_get_by_query__validates_comparison sosw/components/test/unit/test_dynamo_db.py::dynamodb_client_UnitTestCase::test_patch__transfers_attrs_to_remove sosw/components/test/unit/test_dynamo_db.py::dynamodb_client_UnitTestCase::test_sleep_db__ sosw/components/test/unit/test_dynamo_db.py::dynamodb_client_UnitTestCase::test_sleep_db__fell_asleep sosw/components/test/unit/test_dynamo_db.py::dynamodb_client_UnitTestCase::test_sleep_db__get_capacity_called sosw/components/test/unit/test_dynamo_db.py::dynamodb_client_UnitTestCase::test_sleep_db__wrong_action
sosw/components/dynamo_db.py
sosw/components/dynamo_db.py