from fastapi import Depends def query(q:Optional[str] = None): return q def sub_query(q: str = Depends(query), last_query: Optionnal[str] = None): if not q: return q return last_query @app05.get('/sub_dependency') def sub_dependency(final_query: str = Depends(sub_query, use_cache=True)): return {'sub_dependency': final_query}