With the zlib module, it seems like unconsumed_tail is only empty if there's no more data to retrieve, meaning that to decompress our payload safely with max_length we can do something like this:
process_output(d.decompress(data, max_length))
while d.unconsumed_tail:
process_output(d.decompress(d.unconsumed_tail, max_length))
When using isal.isal_zlib, it seems that there are situations where unconsumed_tail is empty and there's still more data available that will be returned if you call d.decompress(b""). It looks to me like there's no possible way for me to know if I've retrieved all the pending data except by making a redundant call and receiving b"".