<P> Upon Dean's request, Death retrieves Sam's soul from the Cage and returns it to him at the end of the sixth season's mid-season finale "Appointment in Samarra". He gives Sam's mind a "protective wall" to prevent any negative effects it might have on him otherwise, but Death also warns him not to scratch at the wall he has built, or his memories from Hell will destroy him . However, Castiel, in an attempt to distract Dean and Bobby while he attempts to enter Purgatory, brings down the wall, ultimately causing Sam to remember his time in Hell . In the season finale, Sam spends much of the episode attempting to recoup his shattered soul, including the memories of his soulless self and tortured self . Once complete, he reawakens, though still struggling with the visions of the Cage that his soul endured . </P> <P> After Castiel's actions result in the release of the Leviathans--God's first creations--Sam is left struggling with the restoration of his memories of his time in Hell, even if he remains dedicated to helping Dean and others stop the Leviathans . During this time, he has a reunion with his old Kitsune friend, Amy Pond, who has become a mortician feeding on the dead to sustain her, although Dean nevertheless kills her when he discovers that she has been killing to help her sick son . As Sam experiences hallucinations of Lucifer taunting him with the idea that he is still in Hell, he initially tries to control them by focusing on wounds he sustains in the real world, but matters become worse when he is forced to rely on information from the hallucination to save Dean . As his mental state becomes worse, Sam foregoes sleep to stop his visions, but is sent to an asylum when he is hit by a car while running away from Lucifer . While trying to find a healer who may be able to repair Sam, Dean encounters an amnesiac Castiel, who, when restored to his full powers, sacrifices himself by taking Sam's mental damage . Sam is shown to possess great guilt about this and rejects hope that Bobby's ghost may be helping them out after an attempt to communicate with him fails . Sam is initially happy when it is shown that Bobby's ghost is there helping them, but changes his mind after Bobby shows more and more signs of becoming a vengeful spirit . During the final battle at Sucrocorp, Sam rescues Kevin Tran--a Prophet who can read the Word of God--and is horrified to hear of Dick Roman's plan to kill all the skinny people in the world through poison in their coffee creamers . He and Kevin head to the lab where they find Dick Roman being killed by Dean and Castiel . After Dick explodes, Dean and Castiel disappear and Crowley appears and takes Kevin, leaving Sam completely on his own, not knowing Dean and Castiel are now trapped in Purgatory . </P> <P> The year Sam spends while Dean and Castiel are trapped in Purgatory is revealed through various flashbacks in the first half of the season . Now left on his own, Sam believes that Dean had been killed when Dick exploded, and gives up hunting . After several months, he accidentally runs over a stray dog and, panicked, takes it to an animal hospital . The veterinarian who saves the dog's life--Amelia Richardson--convinces Sam to take responsibility for the stray by adopting it . Despite a rocky start, Sam and Amelia fall in love and even buy a house together in Kermit, Texas . They later find out that her husband Don, who she had believed was killed in action, was actually still alive . Sam wants to stay with Amelia, but ultimately decides to leave and give her the opportunity to reconnect with Don . </P> <P> In the season premiere "We Need to Talk About Kevin", Sam runs into Dean and learns that Dean had just escaped from Purgatory; upon learning about what Sam had been doing the past year, Dean is upset that Sam had not even tried to save him or continued hunting . They find out that Kevin had managed to escape from Crowley six months ago and left Sam a string of desperate voice messages, begging for help . Sam feels guilty and joins Dean in tracking down Kevin, who reveals that he has discovered a passage in the Word of God that would banish all demons from Earth forever . The spell requires three trials be performed by one person . Although Dean tries to do it himself in order to protect Sam from any possible consequence of the trials, Sam ends up completing the first trial (killing a hellhound and bathing in its blood) in "Trial and Error" to protect Dean; he persuades his brother to let him finish the rest by reasoning that Dean would be all - too - willing to sacrifice himself for the trials whereas Sam would fight so that both of them could live . However, taking on the trials quickly begins "damaging" Sam, which worries Dean . </P>

What did sam do while dean was in purgatory
find me the text answering this question