The Netziv (introduction to Bereishis) beautifully describes the yashrus of our patriarchs, which was so great that even Bilam was moved by it, and the contrast between them and Bilam. What follows is a presentation of the Netziv's ideas and the lesson of balance contained therein.
I
"May my soul die the death of the upright (literally straight - yesharim) and may my end be like his (Yisrael's)" (Bamidbar 23:10). The upright, in the context of Bilam's bracha, refers to the yersharim of Yisrael (Rashi). Specifically, the yesharim are Avraham, Yitzchak and Yaakov, after whom Bereishis is called "Sefer Hayashar", the book of the upright patriarchs (Avodah Zara 25a).
The Netziv refers to Devarim (32:4), "Hashem, perfect is His work, for all His ways are justice, a G-d of faith without injustice, righteous and upright (yashar) is He". Tziduk Hadin - Acceptance of Judgment, recited when a person is buried, begins with this passuk. The passuk is an Acceptance of Judgment on a national scale, referring to the destruction of the two batei mikdash.
The second Beis Hamikdash was destroyed in a "crooked and twisted generation" (Devarim 32:5). They were righteous and learned, but not straight in the ways of the world. Because of the baseless hatred in their hearts, they suspected anyone who served Hashem differently than themselves of being a Saducee and an apikores. Hashem is upright and does not tolerate a tzadik who is not upright in the ways of the world. Even if he acts for the sake of Heaven, he causes the destruction of society. Therefore, the second Bais Hamikdash was destroyed by Hashem, the Yashar.
The patriarchs were not only tzadikim in serving and loving Hashem. They were al so yesharim, concerned with the nations despite their paganism and immorality. For example, Avraham hated the people of Sodom who were very wicked (Bereishis 13:13), and were guilty of the sodomy named for them (Rashi 19:5). Yet he prayed repeatedly for their survival (18:23-32), literally as the father of nations (17:5). Even if a son strays, the father seek his peace and welfare. Yitzchak, regarding Avimelech (26:20-31), and Yaakov, concerning Lavan (31:26-420, did the same. Therefore, Bereishis is called Sefer Hayashar, the book of the upright patriarchs.
Bilam was not upright like the patriarchs. He was sexually perverse (Avodah Zara 4b) and he attempted to destroy Am Yisroel. Yet he longed to die the death of the upright, presumably by repenting. However, after failing to curse Am Yisroel, he deviously advised the sexual entrapment which led to a plague (Rashi Bamidbar 24:14). After receiving full financial reward for this advice, he deserved and met the violent death (31:8, and Rashi) of an unrepentant pervert.
II
Notwithstanding their concern for the welfare of sinners, our patriarchs insisted on both physical and existential separation from them. Avraham Ha'ivri (Bereishis 14:13) was on the other side, separated from the entire pagan world (Medrash Rabba). He parted company from his wicked nephew Lot (Bereishis 13:8-12), only thereafter meriting Hashem's instruction (Rashi 13:14). Yitzchak was separated from the idolatrous and sexually immoral Yishmael (Rashi 21:9). Yaakov separated from Lavan (31:49), Esav (33:12-17), and Pharoh (44:34 see Rashi).
Love for others and separation from them are not contradictory. "Yisroel dwelled secure, solitary, the essence of Ya'akov" (Devarim 33:28). The Netziv renders "secure" as calm, with love towards others, without competing with other nations. "Solitary" means without excessive mingling with the nations, fellowship which could lead to intermarriage. These two characteristic represent the essence of Yaakov, and his wish for his descendants.
The balance between separation from sinful practice and thought, and maintaining uprightness in the ways of the world, was achieved by our righteous and upright patriarchs. May we successfully achieve that balance and hasten the rebuilding of the Beis Hamikdash.