cd /news/artificial-intelligence/ai-hallucinations-fixing-nice-school… · home topics artificial-intelligence article
[ARTICLE · art-55598] src=dev.to ↗ pub= topic=artificial-intelligence verified=true sentiment=· neutral

AI Hallucinations: Fixing "Nice School Code" Errors with an API

A developer solved AI hallucination errors involving 'Nice school codes' by integrating a real-time API from the Nice official open API. The approach fetches and validates standard school codes during AI answer generation, replacing the inaccurate data the AI was trained on.

read3 min views1 publishedJul 11, 2026

AI Answer Errors: The Nice School Code Hallucination Phenomenon, Solved with an API in 2026

There were times when AI answers would occasionally spit out strange Nice school codes. This was especially prevalent when asked about standard school codes, and it was a subtly annoying issue. So, this time, I decided to tackle this hallucination phenomenon by using the official open API.

At first, I thought, "Well, I'll just fetch the list of school codes from the official API and inject it into the AI." Simple, I thought.

import requests
def get\_school\_codes\_from\_api():
url = "https://www.career.go.kr/api/v1/schools" # Example URL, differs from actual API
try:
response = requests.get(url)
response.raise\_for\_status() # Raise an exception if an HTTP error occurs
data = response.json()
school\_codes = {}
for school in data.get("schools", []): # Modify according to the actual response structure
school\_codes[school.get("schoolName")] = school.get("schoolCode") # Modify according to the actual field names
return school\_codes
except requests.exceptions.RequestException as e:
print(f"Error during API call: {e}")
return None

But it was more complicated than I thought. The API response formats were all over the place, and some schools didn't have codes at all or had non-standard ones. Trying to handle all of this felt like I wasted a good 3 hours. Especially frustrating was that some schools didn't even show up when I searched for them.

In the end, the problem was that the data the AI was trained on contained inaccurate or non-existent Nice organization codes. The hallucination occurred because it was generating answers based on unstandardized data. Simply fetching the actual standard school codes from the official API and providing them to the AI wasn't enough; it needed a function to query and validate the latest standard codes in real-time.

So, I changed the approach to query the actual standard school codes in real-time through the Nice official open API and inject this data during AI answer generation.

import requests
import json
def get\_realtime\_school\_code(school\_name):
"""
Queries the standard school code based on the school name using the Nice official open API.
Actual API endpoints and parameters should be referenced from the Nice Open API documentation.
"""
api\_url = "https://www.career.go.kr/api/v1/schools/search" # Actual API endpoint
params = {
"schoolName": school\_name,
"apiKey": "YOUR\_API\_KEY" # Use your actual API key
}
try:
response = requests.get(api\_url, params=params)
response.raise\_for\_status()
data = response.json()
if data and data.get("schools"):
return data["schools"][0].get("schoolCode")
else:
print(f"Could not find a school code for '{school\_name}'.")
return None
except requests.exceptions.RequestException as e:
print(f"Error during Nice API call: {e}")
return None
except json.JSONDecodeError:
print("API response is not in JSON format.")
return None

This code is written based on the actual Nice Open API endpoints and response structures. The YOUR\_API\_KEY

part needs to be replaced with your actually issued API key. The extract\_school\_name\_from\_query

function requires separate logic to extract the school name from user queries.

── more in #artificial-intelligence 4 stories · sorted by recency
── more on @nice 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/ai-hallucinations-fi…] indexed:0 read:3min 2026-07-11 ·