Since two-book deals seem to be fairly common and the second book should be similar to the first in terms of genre and audience, I’m wondering how similar the second book should be. I realize I’m putting the cart before the horse a bit as I’m just getting ready to query, but as I’m starting my next novel I was curious. As an example, if the first is upmarket historical fiction, can the second be contemporary? How different is too different?
The cart is not only in front of the horse, it's been loaded on a barge and shipped downriver. The horse can't even see it anymore.
This question falls in the rodent-wheel category: things you should not worry about at all right now.
The reason is that what you will need for your second novel is entirely dependent on the deal you strike for Book #1. The editor/publisher will have a LOT of say in it, and you can't begin to guess what they want cause the book hasn't been subbed, let alone sold.
Even if there is a common practice of what kind of book it will most likely be, you may not be in that category.
If you're thinking about what to write while you're on submission to agents, write what you want. When you acquire representation, you and your agent will put your heads together to strategize what's next.