Almost everyone will agree that neither extreme is correct. That is to say, that almost no one will interpret every word of the Torah literally, and almost no one will interpret every word of the Torah allegorically. The real question is what the balance is. How do we determine which parts of the Torah should be interpreted literally, and which parts should be interpreted allegorically? And, of course, this is subject to much debate.
The first systematic methodology was given by R. Sa'adia Gaon. In Emunot V'Deiot 7:2 he lists four criteria for deviating from the literal meaning of Scripture:
- When Scripture contradicts the senses.
- When Scripture contradicts reason.
- When Scripture contradicts Scripture.
- When there is a rabbinic tradition.
He very clearly states that these and only these are valid reasons for deviating from the literal meaning.
And so I declare, first of all, that it is a well-known fact that every statement found in the Bible is to be understood in its literal sense except for those that cannot be so construed for one of the following four reasons. It may, for example, either be rejected by the observation of the senses, such as the statement: And the man called his wife's name Eve; because she was the mother of all living (Gen. 3:20), whereas we see that the ox and the lion are not the offspring of womankind. Hence we must needs conclude that the implication of the statement embraces human descendants only.
Or else the literal sense may be negated by reason, such as that of the statement: For the Lord thy God is a devouring fire, a jealous God (Deut. 4:24). Now fire is something created and defective, for it is subject to extinction. Hence it is logically inadmissible that God resemble it. We must, therefore, impute to this statement the meaning that God's punishment is like a consuming fire, in accordance with the remark made elsewhere in scripture: For all the earth shall be devoured with the fire of My jealousy (Zeph. 3:8).
Again, [the literal meaning of a Biblical statement may be rendered impossible] by an explicit text of a contradictory nature, in which case it would become necessary to interpret the first statement in a non-literal sense. Thus, for example, it is said in Scripture: Ye shall not try the Lord your God, as ye tried Him in Massah (Deut/ 6:16). And it is also said, on the other hand: And try Me now herewith... if I will not open you the windows of heaven (Mal. 3:10). Now the point wherein these two statements agree is that we must not test our Lord as to whether He is able to do a certain thing, as they did of whom it is reported: And they tried God in their heart by asking food for their craving. Yea, they spoke against God; they said: "Can God prepare a table in the wilderness?" (Ps. 78:18, 19.) It is to these that the remark as ye tried Him in Massah refers. It is, however, permissible for a servant of God to test his Master by asking whether it be possible for Him to create a miracle in his behalf. Such a request was indeed made by Gideon, who said: Let me make trial, I pray Thee, but this once with the fleece (Judg. 6:39). It was also done by Hezekiah (II Kings 20:8) and others.
Finally any Biblical statement to the meaning of which rabbinic tradition has attached a certain reservation is to be interpreted by us in keeping with this authentic tradition. Thus it has been transmitted to us that the punishment of stripes consists of thirty-nine blows, although Scripture states: Forty stripes he may give him (Deut. 25:3). We therefore adopt the view that this is just a rough way of saying that there be thirty-nine stripes. The text of Scripture has merely expressed this thought in round numbers, as it has done in the statement: After the number of the days in which ye spied out the land, even forty days, for every day a year shall ye bear your iniquities, even forty years (Num. 14:34). For in reality there were only thirty-nine years, since the first year of Israel's sojourn in the wilderness did not enter into this punishment.
There exist, then, only these four possible reasons for a non-literal interpretation of the verses of Sacred Writ, there being no fifth. (Rosenblatt translation)
R. Abraham Ibn Ezra in his commentary to Exodus 20:1 discusses commandments that appear to contradict sense:
וחלילה חלילה שתהיה מצוה אחת מהן מכחשת שקול הדעת רק אנחנו חייבים לשמור כל אשר צונו השם בין שנגלה לנו הסוד בין שלא נגלה ואם מצאנו אחת מהן מכחשת שקול הדעת אינו נכון שנאמין בו כי הוא כמשמעו רק בספרי חכמינו ז"ל נבקש מה טעמו אם היא על דרך משל ואם לא מצאנו זה כתוב נבקש אנחנו ונחפש בכל יכלתנו אולי נוכל לתקן אותה ואם לא יכלנו נניחה כאשר היא ונודה שלא ידענו מה היה כמו ומלתם את ערלת לבבכם וכי הוא צונו שנרצחנו כאכזרי
And heaven forfend that there should be a commandment, one of them, that contradicts the assessment of intelligence; we just are obligated to keep all that God commanded us, whether the secret has been revealed to us or whether it has not been revealed. And if we find one of them contradicting the assessment of intelligence it is not proper that we believe about it that it is as it sounds. Instead we should search its reason in the books of our Sages of blessed memory, [to see] if it is by way of parable. And if we do not find this written, we [ourselves] should search and seek with all our ability that we may perhaps be able to fix it. And if we are unable, we should leave it as it is and acknowledge that we don't know what it is, like [the commandment of] and you shall circumcise the foreskin of your heart — did [God] command us that we should kill ourselves like a cruel [person]?!
He seems to be of the opinion that anything which contradicts sense must be reinterpreted, and if we can't find a way to reinterpret it we should put it aside. Notably, this is specifically not limited to narrative portions of the Torah.
Rambam may be the one most famously held as the champion of non-literal interpretation. Much of his writings are dedicated to eradicating the literal interpretations of verses which corporify God. As I mentioned in this answer, Rambam wrote that he could easily interpret the account of creation against the literal meaning of a created universe, if not for the fact that an eternal universe would undermine the religion. Indeed, as I mentioned in this answer, he states in Guide for the Perplexed 2:29 that the account of creation is not to be taken entirely literally. Similarly, as I mentioned in the same answer, he interpreted many Scriptural narratives as occurring in dreams/visions, even though the literal reading of the text implies that they happened in real life, as he explains in Guide for the Perplexed 2:41-42.
He did assert that certain things had to be literal, though. As I mentioned in this answer in Guide for the Perplexed 3:50 he insisted that there was a literal person Adam created.
Like Rambam, Ralbag interpreted many passages non-literally. However, as I explained in this answer, he strongly cautioned against abusing the policy of allegorization, even criticizing Rambam for invoking it unnecessarily, noting that excessive alllegorization can destroy the entire Torah.
R. Joseph Ibn Kaspi also followed Rambam in interpreting some passages non-literally, but also criticized Rambam for excessive allegorization. As I mentioned in this answer, he argued that by following Rambam's lead it would be possible to allegorize everything, and we would be left with no Torah.
Ramban also strongly criticized Rambam's interpretations. In his commentary to Genesis 18:1 he writes:
In the book Moreh Nebuchim it is said that this portion of Scripture consists of a genearal statement followed by a detailed description. Thus Scripture first says that the Eternal appeared to Abraham in the form of prophetic visions, and then explains in what manner this vision took place, namely, that he [Abraham] lifted up his eyes in the vision, and lo, three men stood by him, and he said, if now I have found favor in thy eyes. This is the account of what he said in the prophetic vision to one of them, namely, the chief.
Now if in the vision there appeared to Abraham only men partaking of food, how then does Scripture say, And the Eternal appeared to him, as G-d did not appear to him in vision or in thought? Such is not found with respect to all the prophecies. And according to his words, Sarah did not knead cakes, nor did Abraham prepare a bullock, and also, Sarah did not laugh. It was all a vision! If so, this dream came through a multitude of business, like dreams of falsehood, for what is the purpose of showing him all this! Similarly did the author of Moreh Nebuchim say in the case of the verse, And a man wrestled with him, that it was all a prophetic vision. But if this be the case, I do not know why Jacob limped on his thigh when he awoke! And why did Jacob say, For I have seen an angel face to face, and my life is preserved? The prophets did not fear that they might die on account of having experienced prophetic visions. Jacob, moreover, had already seen a greater and more distinguished vision than this many times, in prophetic visions, he had also seen the Revered Divinity. Now according to this author's opinion, he will find it necessary for the sake of consistency to say similarly in the affair of Lot that the angels did not come to his house, nor did he bake for them unleavened bread and they did eat. Rather, it was all a vision! But if Lot could ascend to the height of a prophetic vision, how did the wicked and sinful people of Sodom become prophets? Who told them that men had come into Lot's house? And if all these [i.e., the actins of the inhabitants of Sodom], were part of prophetic visions, then it follows that the account related in the verses, And the angels hastened Lot, saying: Arise thake thy wife. ...And he said, Escape for thy life... See, I have accepted thee, as well as the entire chapter is but a vision, and if so, Lot could have remained in Sodom! But the author of the Moreh Nebuchim thinks that the events took place of themselves, but the conversations relating to all matters were in a vision! But such words contradict Scripture. It is forbidden to listen to them, all the more to believe in them! (Chavel translation)