How to validate that a nested field is not a list using Ecto?

If a use Ecto.Changeset.cast_embed and I call data field with a string, returns this error:

[data: {"is invalid", [validation: :embed, type: :map]}]

If I call with a list, returns this exceptions:

     ** (Ecto.CastError) expected params to be a :map, got: `[]`

To solve this problem, is a good solution to define this in the Data module?

def changeset(data, params) when is_list(params), do: add_error(changeset, :data, "should be a map")

def changeset(data, params) do
# normal changeset ...
end