# Key validation

Starting with Python client 18.1.0, the Aerospike Python client can validate certain kinds of dictionaries to check for valid inputs.

## Client configuration

The [client config dictionary](https://aerospike-python-client.readthedocs.io/en/latest/aerospike.html#client-config) contains configuration information for connecting an application to an Aerospike database server. To ensure the client config dictionary contains no invalid keys, include the key-value pair `"validate_keys": True`.

The following example demonstrates `validate_keys` usage:

```python
import aerospike

config = {

    "validate_keys": True,

    "hosts": [

        ("127.0.0.1", 3000)

    ],

    # The correct key is "user", but "username" may be used by mistake

    "username": "user",

    "password": "password"

}

# This call raises a ParamError from aerospike.exception

# Exception message should be:

# "username" is an invalid client config dictionary key

client = aerospike.client(config)
```

For more information on connecting to an Aerospike server, see [Connecting](https://aerospike.com/docs/develop/client/python/connect/).

## Policies

The policy dictionary contains [configuration information](https://aerospike-python-client.readthedocs.io/en/latest/aerospike.html#policy-options) to customize your client connection for optimal command performance and reliability. To ensure the policy dictionary contains no invalid keys, include the key-value pair `"validate_keys": True` in the client config dictionary.

Invalid policy example:

```python
import aerospike

config = {

    "validate_keys": True,

    "hosts": [

        ("127.0.0.1", 3000)

    ],

}

client = aerospike.client(config)

key = ("test", "demo", 1)

# "key_policy" is used instead of the correct key named "key"

policy = {

    "key_policy": aerospike.POLICY_KEY_SEND

}

# This call raises a ParamError from aerospike.exception

# Exception message should be:

# "key_policy" is an invalid policy dictionary key

client.get(key, policy=policy)
```

## Metadata dictionary

The [`metadata` dictionary](https://aerospike-python-client.readthedocs.io/en/dev/client.html#metadata-dictionary) holds two keys: `"ttl"` and `"gen"`. To ensure the `metadata` dictionary contains no invalid keys, include the key-value pair `"validate_keys": True` in the `config` dictionary.

Invalid key example:

```python
import aerospike

config = {

    "validate_keys": True,

    "hosts": [

        ("127.0.0.1", 3000)

    ],

}

client = aerospike.client(config)

key = ("test", "demo", 1)

meta = {

    "ttl": 100,

    # "generation" should be "gen"

    "generation": 4

}

# This call raises a ParamError from aerospike.exception

# Exception message should be:

# "generation" is an invalid record metadata dictionary key

client.put(key, bins={"a": 1}, meta=meta)

client.close()
```