You can do it if you write a custom rrule for your function.   Then you can return @not_implemented("foo") for the terms you don’t want.
Otherwise you are relying on the compiler to eliminate “dead code” for unused results.
In contrast, Enzyme.jl has separate explicit rules for constant arguments — see the post by @ChrisRackauckas contrasting Enzyme and Zygote rules: What's the state of Automatic Differentiation in Julia January 2023? - #6 by ChrisRackauckas