Welcome to the Community!
My two cents on this:
If you are using a RAG-based approaches that involve chunking the document, then it is quite possible that the table of contents gets chunked into different pieces. In that case, only the first chunk might actually contain the identifier “table of contents” and be returned as part of the retrieval process while the second part might not be recognized as being part of the table of contents and as such not be returned as part of retrieval. To overcome this, you could increase your chunk size.
Another simplified way to achieve your goal might be to just pass the model as context the first ~10 or so pages of the book/document (which should include the table of contents) and then just ask it to return the information.
Finally, there’s a also a dedicated thread discussing options for obtaining a document outline. It might be too specialized for your case, but dropping the link here anyway for reference: