There are many different types of NPCs. Consider e.g. Minecraft villagers, that doesn't have a story-purpose, but do serve functions such as trading that could also be augmented by dialogue details.
But even for story-driven games, you can signal when you're "done" extracting story-related details in various ways, by e.g. prompt the NPC to include dialogue element A,B,C when it fits the conversation, keep track of which were output (you can make it output a marker to ensure it's easy to track even if the dialogue element has been worded differently), and have it get annoyed and tell you it doesn't have more to tell you or similar as the repetition adds up.