Thought to be one of Selma Lagerlöf's earliest works, "The Rat Trap" is a short story that was likely written in the 1880s, before excerpts of Lagerlöf's first novel Gösta Berling's Saga were published in a Swedish weekly publication. The story focuses on a vagabond who makes his meager living by building rat traps with bits of material he manages to beg from shopkeepers and farmers. He sells them in the towns he passes through. The rat trapper, who goes unnamed until the very end of the story (where he adopts the name of Captain von Ståhle), wears his rat traps like pendants around his neck.
"The Rat Trap" was published in the original Swedish as "Råttfällan" in Lagerlöf's 1933 collection of stories, Host. The collection was then translated to English and published as Harvest two years later. The story centers around an allegory that the protagonist thinks of in the course of his travels—that the whole world is a rat trap, and that life, with all of its temptations and moments of hope, is laden with bits of "cheese" and "meat" that seduce the living onto the course of their downfall.
Though its themes may not necessarily align with most children's tales, "The Rat Trap" clearly proposes a moral lesson. Lagerlöf begins the tale by depicting the protagonist's deeply cynical view that the whole world is a rat trap, but she then demonstrates how his perception is shaped largely by how he's treated by other people. In the course of the story, the protagonist encounters other lonely people in various levels of comfort and economic stability. He is the recipient of the kindness of strangers and is treated particularly well by the Ironmaster, who mistakes him for his old army buddy. The radical kindness of the Ironmaster's daughter ultimately changes the protagonist's perspective and demonstrates the moral of the story: that many people rise or sink to the expectations of others. Lagerlöf shows her reader that it matters how we treat others, because it will likely inform how they interact with the world.
Lagerlöf's training and professional experience as a teacher, along with her publication of The Adventures of Nils, place her firmly in a tradition of writing and inventing fables and didactic tales meant to teach children how to behave and mold them into empathetic young adults. Lagerlöf wrote The Adventures of Nils as a primer to be used to teach children language skills, and over a century later, the English translation of "The Rat Trap" is used in English curricula around the world.