quality:corruption, linguistic:translation, structural:expansion, stylistic:style_transfer
Lê Thánh Tông (ruled 1460–1497)

Quang Thuận Hoàng Đế (光順皇帝), whose reign was named Hồng Đức Thịnh Thế (洪德之盛治, "Prosperous reign of Hồng Đức"), instituted a wide range of government reforms, legal reforms, and land reforms. He restarted the examination system for selecting men for important government positions. He reduced the power of the noble families and reduced the degree of corruption in the government. He built temples to Confucius throughout the provinces of Đại Việt. In nearly all respects, his reforms mirrored those of the Ming dynasty. Thánh Tông was strongly influenced by his Confucian teachers and he resolved to make Việt Nam more like the Ming dynasty with its Neo-Confucianist philosophy and the key idea that the government should be run by men of noble character as opposed to men from noble families. This meant that he needed to take power away from the ruling families (mostly from Thanh Hóa province) and give power to the scholars who did well on the official examinations. The first step on this path was to revive the examination process, which had continued sporadically in the 1450s. The first examination was held in 1463 and, as expected, the top scholars were men from elsewhere- usually from the river delta surrounding the capital, not from Thanh Hóa. In 1467, Lê Thánh Tông changed the name of the state to "Thiên Nam" (Heavenly South) to make the parallel position with their northern neighbor and shared classical culture more explicit.

Thánh Tông encouraged the spread of Confucian values throughout Vietnam by having " temples of literature " built in all the provinces. There, Confucius was venerated and classic works on Confucianism could be found. He also halted the building of any new Buddhist or Taoist temples and ordered that monks were not to be allowed to purchase any new land.

Lê Thánh Tông introduced reforms designed to replace the Thanh Hoá oligarchy of Dai Viet's southern region with a corps of bureaucrats selected through the Confucian civil service examinations. Following the Chinese model, he divided the government into six ministries: Finance, Rites, Justice, Personnel, Army, and Public Works. Nine grades of rank were set up for both the civil administration and the military. A Board of Censors was set up with imperial authority to monitor governmental officials and reported exclusively to the emperor. However, governmental authority did not extend all the way to the village level. The villages were ruled by their own councils in Vietnam.

With the death of Nguyễn Xí in 1465, the noble families from Thanh Hóa province lost their leader. Soon they were mostly relegated to secondary positions in the new Confucian government of Thánh Tông. However, they still retained control over Vietnam's armies as the old general, Đinh Liệt, was still in command of the army. In the same year, Vietnam was attacked by Ryukyuan pirates from the northeast. This was dealt with by sending additional forces to the north to fight the pirates. Thánh Tông also sent a military force to the west to subdue the Ai-lao mountain tribes that was raiding the northwest border. In 1469, all of Vietnam was mapped and a full census was taken, listing all the villages in the Empire. Around this time the country was divided into 13 dao (provinces). Each was administrated by a Governor, Judge, and the local army commander. The emperor Thánh Tông also ordered that a new census should be taken every six years. Other public works that were undertaken included building and repair of granaries, using the army to rebuild and repair irrigation systems after floods, and sending out doctors to areas afflicted by outbreaks of disease. Even though the emperor, at 25, was relatively young, he had already restored Vietnam's stability, which was a marked contrast from the turbulent times marking the reigns of the two emperors before him.

Article 344 of the Nguyen dynasty code and Article 305 of the Le dynasty code both forbade self-castration and castration of Vietnamese men. Self-castration of Vietnamese men was banned by Lê Thánh Tông, the emperor, in 1464.

The Vietnamese under Emperor Le Thanh Tong cracked down on foreign contacts and enforced an isolationist policy. A large amount of trade between Guangdong (Leizhou Peninsula and Hainan) and Vietnam happened during this time. Early accounts recorded that the Vietnamese captured Chinese whose ships had blown off course and detained them. Young Chinese men were selected by the Vietnamese for castration to become eunuch slaves to the Vietnamese. It has been speculated by modern historians that Chinese who were captured and castrated by the Vietnamese were involved in regular trade between China and Vietnam instead of being blown off course, and that they were punished after a Vietnamese crackdown on trade with foreign countries.

A 1499 entry in the Ming Shilu recorded that thirteen Chinese men from Wenchang including a young man named Wu Rui were captured by the Vietnamese after their ship was blown off course while traveling from Hainan to Guangdong 's Qin subprefecture (Qinzhou), after which they ended up near the coast of Vietnam, in the 1460s, during the Chenghua Emperor 's rule (1464–1487). Twelve of them were enslaved to work as agricultural laborers, while the youngest Chinese man, Wu Rui (吳瑞) was selected by the Vietnamese court for castration since he was the only young man in among the thirteen and he became a eunuch at the Vietnamese imperial palace in Thang Long for nearly one fourth of a century. After years of serving the Vietnamese as a eunuch slave in the palace, he was promoted to a position with real power after the death of the Vietnamese ruler in 1497 to a military position in northern Vietnam as military superintendent since his service in the palace was apparently valued by the Vietnamese. However the Lạng Sơn guard soldier Dương Tam tri (Yang Sanzhi) (楊三知) told him of an escape route back to China and Wu Rui escaped to Longzhou after walking for 9 days through the mountains. The local ethnic minority Tusi chief Wei Chen took him into custody, overruling objections from his family who wanted to send him back to Vietnam. Vietnam found out about his escape and sent an agent to buy Wu Rui back from Wei Chen with 100 Jin in payment since they were scared that Wu Rui would reveal Vietnamese state secrets to China. Wei Chen planned to sell him back to the Vietnamese but told them the amount they were offering was too little and demanded more however before they could agree on a price, Wu was rescued by the Pingxiang magistrate Li Guangning and then was sent to Beijing to work as a eunuch in the Ming palace at the Directorate of Ceremonial (silijian taijian 司禮監太監). The Đại Việt sử ký toàn thư records that in 1467 in An Bang province of Dai Viet (now Quảng Ninh Province) a Chinese ship blew off course onto the shore. The Chinese were detained and not allowed to return to China as ordered by Le Thanh Tong. This incident may be the same one where Wu Rui was captured.

Several Malay envoys from the Malacca sultanate were attacked and captured in 1469 by Vietnamese navy as they were returning to Malacca from China. The Vietnamese enslaved and castrated the young from among the captured.

A 1472 entry in the Ming Shilu reported that some Chinese from Nanhai escaped back to China after their ship had been blown off course into Vietnam, where they had been forced to serve as soldiers in Vietnam's military. The escapees also reported that they found out that more than 100 Chinese men remained captives in Vietnam after they were caught and castrated by the Vietnamese after their ships were blown off course into Vietnam in other incidents. The Chinese Ministry of Revenue responded by ordering Chinese civilians and soldiers to stop going abroad to foreign countries. These 100 men were taken prisoner around the same time as Wu Rui and the historian Leo K. Shin believes all of them may have been involved in illegal trade instead of being blown off course by wind. The over 100 Chinese men who were castrated and made into eunuchs by the Vietnamese remained captives in Vietnam when the incident was reported. Both the incidents of the young Chinese man Wu Rui and the more than 100 Chinese men being castrated and used as eunuchs point to possible involvement in trade according to historians John K. Whitmore and Tana Li which was then suppressed by the Vietnamese government instead of them really being blown off course by the wind. China's relations with Vietnam during this period were marked by the punishment of prisoners by castration.

Under the order of Lê Thánh Tông, the official historical text of the Lê dynasty, Đại Việt sử ký toàn thư (大越史記全書), was compiled and finished in 1479. The 15-volume book covered the entirety of Vietnamese history at that point, from the Hồng Bàng dynasty to the enthronement of Lê Thái Tổ.