Check the type of the entity before evaluating the predicate to avoid key path errors.