```python:inference/core/workflows/core_steps/common/query_language/introspection/core.py
from typing import Optional


def _ref_to_def_name(
    schema: dict,
    ref_key: str = "$ref",
) -> Optional[str]:
    """Extract definition name from a JSON Schema object's $ref (e.g. {'$ref': '#/$defs/Foo'} -> 'Foo')."""
    ref = schema.get(ref_key)
    if ref is None:
        return None

    return ref.rpartition("/")[2]
```