boto/boto3 · error · TypeError

Float types are not supported. Use Decimal types instead.

Error message

Float types are not supported. Use Decimal types instead.

What it means

DynamoDB stores numbers as arbitrary-precision decimals; IEEE-754 floats lose precision and cannot round-trip. TypeSerializer._is_number accepts int and Decimal but raises TypeError('Float types are not supported. Use Decimal types instead.') when given a Python float, to prevent silent precision loss.

Solutions

  1. Wrap numeric values with Decimal(str(value)) before storing: Decimal(str(19.99)).
  2. Parse JSON with parse_float=Decimal.
  3. Configure boto3 with DYNAMODB_CONTEXT traps if you need stricter handling.

Example fix

# before
from decimal import Decimal
table.put_item(Item={'price': 19.99})
# after
from decimal import Decimal
table.put_item(Item={'price': Decimal('19.99')})
# or json -> Decimal
import json
obj = json.loads(text, parse_float=Decimal)
Defensive patterns

Strategy: validation

Validate before calling

from decimal import Decimal
def to_decimal(v):
    if isinstance(v, float):
        return Decimal(str(v))
    if isinstance(v, (int, Decimal)):
        return Decimal(v)
    raise TypeError(f'cannot convert {type(v)} to Decimal')
item = {k: to_decimal(v) for k, v in item.items() if isinstance(v, (int, float, Decimal))}

Type guard

from decimal import Decimal
def is_dynamo_number(v) -> bool:
    return isinstance(v, (int, Decimal)) and not isinstance(v, bool)

Try / catch

try:
    table.put_item(Item=item)
except TypeError as e:
    if 'Float types' in str(e):
        item = {k: (Decimal(str(v)) if isinstance(v, float) else v) for k, v in item.items()}
        table.put_item(Item=item)
    else:
        raise

Prevention

When it happens

Trigger: Putting {'price': 19.99} or any item attribute that is a Python float; computing a value with / or math.* and storing the float result directly.

Common situations: JSON parsing with default json.load yields floats; arithmetic producing floats; pandas/numpy float64 values; migrating from a system that allowed floats.

Related errors


AI-assisted analysis of boto/boto3@6e10b029c1 (2026-08-11). Data as JSON: /api/errors/a235c6851b5442ae. Report an issue: GitHub.

Appendix: source

Thrown at boto3/dynamodb/types.py:171

            raise TypeError(msg)

        return dynamodb_type

    def _is_null(self, value):
        if value is None:
            return True
        return False

    def _is_boolean(self, value):
        if isinstance(value, bool):
            return True
        return False

    def _is_number(self, value):
        if isinstance(value, (int, Decimal)):
            return True
        elif isinstance(value, float):
            raise TypeError(
                'Float types are not supported. Use Decimal types instead.'
            )
        return False

    def _is_string(self, value):
        if isinstance(value, str):
            return True
        return False

    def _is_binary(self, value):
        if isinstance(value, (Binary, bytearray, bytes)):
            return True
        return False

    def _is_set(self, value):
        if isinstance(value, collections_abc.Set):
            return True
        return False

View on GitHub (pinned to 6e10b029c1)