DynamoDB ValidationException: Key Does Not Match Schema
Why DynamoDB rejects your request with 'the provided key element does not match the schema' — missing sort key, wrong attribute name, wrong type — and how to fix each case.
On this page
This error stops a lot of first DynamoDB requests cold:
ValidationException: The provided key element does not match the schema
You may also see the closely related variants:
ValidationException: One or more parameter values were invalid: Missing the key <name> in the item
ValidationException: The number of conditions on the keys is invalid
All of them mean the same thing: the key you sent doesn’t match the table’s primary key definition. DynamoDB validates the shape of your key before it does any work, and it’s strict — one wrong field and the whole request is rejected.
First, know your table’s key schema
Every fix starts here. Look up exactly what the table expects:
aws dynamodb describe-table --table-name Orders \
--query "Table.{Keys:KeySchema,Attrs:AttributeDefinitions}"
That tells you the partition key, the sort key (if any), and the type of each (S, N, or B). Your request must provide exactly those attributes — no more, no fewer — with matching types. See Primary keys for how partition and sort keys work.
Cause 1: Missing the sort key
On a table with a composite primary key (partition + sort), GetItem, PutItem, UpdateItem and DeleteItem all require both key attributes. Sending only the partition key triggers the error:
// Table key schema: pk (partition) + sk (sort)
await client.send(new GetItemCommand({
TableName: "Orders",
Key: { pk: { S: "USER#42" } } // ❌ sk is missing
}));
await client.send(new GetItemCommand({
TableName: "Orders",
Key: { pk: { S: "USER#42" }, sk: { S: "ORDER#1001" } } // ✅ both keys
}));
If you only have the partition key and want every item under it, that’s a Query, not a GetItem:
new QueryCommand({
TableName: "Orders",
KeyConditionExpression: "pk = :pk",
ExpressionAttributeValues: { ":pk": { S: "USER#42" } }
});
Cause 2: Wrong attribute name
Key attribute names are exact and case-sensitive. If the table’s partition key is pk but you send PK, id, or userId, it won’t match — even if the value is correct.
Key: { PK: { S: "USER#42" }, sk: { S: "ORDER#1001" } } // ❌ "PK" ≠ "pk"
Copy the names straight from describe-table rather than from memory.
Cause 3: Wrong data type
The value’s type has to match the attribute definition. A key defined as Number (N) must receive a number, not a string:
// Table defines id as N
Key: { id: { S: "42" } } // ❌ sent as String
Key: { id: { N: "42" } } // ✅ sent as Number (note: N values are strings in wire format, but typed N)
This one hides easily when ids arrive from JSON, query params, or a language that stringifies numbers. If you use the Document Client / higher-level mappers, make sure the runtime value is a JS number, not a "string".
Cause 4: Extra attributes in the Key
The Key map may contain only the primary key attributes. Including a non-key attribute (say status or email) to “narrow” the lookup is invalid — you’ll get the schema-mismatch error. Filter on non-key attributes with a FilterExpression on a Query, or a ConditionExpression on a write, not by stuffing them into Key.
Cause 5: Querying with the wrong key condition
On Query, the KeyConditionExpression must reference the partition key with equality (pk = :pk) and, optionally, the sort key with a supported comparison. Referencing a non-key attribute, or using a range operator on the partition key, produces validation errors in the same family.
Diagnostic checklist
- Run
describe-table— note the exact key names, order, and types. - Composite key? Ensure you send both partition and sort key on single-item ops.
- Match names exactly (case-sensitive).
- Match types — a Number key needs a number, not a quoted string.
- Put only key attributes in
Key; move everything else to a filter/condition. - Only have the partition key? Switch from
GetItemtoQuery.
Stop guessing the schema
Half of these bugs come from not having the table’s key schema in front of you while you write the request. Tablyne shows each table’s partition key, sort key and their types right in the UI, and lets you build correct queries visually — so a key mismatch is obvious before you ever run the call. Download Tablyne free to model and query your tables without second-guessing the schema.
Frequently asked questions
What does 'the provided key element does not match the schema' actually mean?
You sent a key that doesn't match the table's defined primary key — either a missing sort key, an extra attribute, a wrong attribute name, or a wrong data type. DynamoDB validates the key shape before doing anything, and rejects the whole request if it's off by even one field.
Why does GetItem need the sort key when I only know the partition key?
GetItem addresses exactly one item, so it requires the full primary key — partition key AND sort key on a composite-key table. To fetch all items under a partition key, use Query with a key condition on the partition key instead of GetItem.
Can a wrong data type cause this error?
Yes. If your key attribute is defined as a Number (N) but you send a String (S) — for example an id sent as "42" instead of 42 — DynamoDB treats it as a schema mismatch and rejects the request.