Police say the child was walking to the Morton McMichael Elementary School on 38th Street and was just three blocks away when the incident happened at 8:15 a.m. Monday.
Police say an older boy grabbed the victim, dragged him into an alley and assaulted him. The victim then ran to the school and reported what had happened.
Action News spoke with the victim's cousin shortly after she received the word of the incident.
"I said 'what's going on?' They said, 'he'd been raped.' I said, 'Raped at the school? What's going on? This is crazy. Kids can't even go to school, this is crazy,'" the cousin said.
Officers drove the boy around the neighborhood looking for the suspect. He's described as about 14 years old and police say he was wearing a school uniform with a red shirt and blue pants.
Because of that uniform, police do not believe he goes to a nearby school, as none of the schools in the immediate area require that clothing.
He apparently ran off after the assault and police spent the morning scouring the neighborhood.
When word got out, other parents came running to the school to check on their children.
"All my children go to school at McMichael as well. So I'm just on my way to make sure none of my children were raped this morning," parent Shakeya Richards said.
"I'm in shock. I can't move. Oh my god," Sylvia D., another student's grandparent, said.
The assault happened a few blocks from the school, but some parents worry that recent school funding cuts have affected security.
The district says that's not an issue.
"It happened not only well off school property, also, keep in my mind, we made no cuts to our police force," Philadelphia School District spokesman Fernando Gallard said.
The school district says counselling will be made available to the 12-year-old victim and his family.
Anyone with information is asked to contact Philadelphia Police at 215-686-TIPS (8477), text a tip to PPD TIP (773847) or through PhillyPolice.com.