# flatten_dict

> **Function** in `langchain_community`

📖 [View in docs](https://reference.langchain.com/python/langchain-community/callbacks/utils/flatten_dict)

Flatten a nested dictionary into a flat dictionary.

## Signature

```python
flatten_dict(
    nested_dict: Dict[str, Any],
    parent_key: str = '',
    sep: str = '_',
) -> Dict[str, Any]
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `nested_dict` | `dict` | Yes | The nested dictionary to flatten. |
| `parent_key` | `str` | No | The prefix to prepend to the keys of the flattened dict. (default: `''`) |
| `sep` | `str` | No | The separator to use between the parent key and the key of the flattened dictionary. (default: `'_'`) |

## Returns

`dict`

A flat dictionary.

---

[View source on GitHub](https://github.com/langchain-ai/langchain-community/blob/4b280287bd55b99b44db2dd849f02d66c89534d5/libs/community/langchain_community/callbacks/utils.py#L46)