Back to the LMS journey

DecidedStop 8 of 15

Checking AI answers in Python, with a local check as backup

The LMS can check an AI answer in a Python service or locally. A part called the gateway decides which result the learner gets. It falls back to the local check when Python fails, and logs the route each time.

The question

Before a learner sees an AI answer, the LMS checks it against the lesson. It has two checkers that can do this. One is a LMS · LMS AI Core · The Laravel sideGateway and fallbackIn live mode, Laravel uses the result from the Python service. If the service is too slow or fails, Laravel switches to its own local check. So nothing goes out unchecked.See it in the LMS build inside Laravel, the main LMS application. The other is in a separate Python service. The gateway is the code that chooses between them. Which LMS · LMS AI Core · The AI serviceClaim checkingSplits an answer into claims, which are single statements, and checks that the lesson supports each one. It also spots clashes in numbers, dates and names. And it spots clashes in quotes, in the order of things, and where one side says “not”.See it in the LMS build’s result does the learner get? And how can anyone tell afterwards?

What made it hard

A backup that works is easy to miss. The learner gets a reply either way. So a good reply can be mistaken for a Python call that worked.

What I chose

The gateway picks a route for each answer. On the live route, the learner gets the Python checker’s result. The live route needs three settings to be on. These are the switch for the separate service, the switch for live Python checking, and Python mode. An optional health check, which asks the Python service if it is working, can also block the call. If the call takes too long or the service sends back an error, the gateway switches to the local check. That is the fallback route.

The shadow route is for comparing the two. The learner gets the local check’s result. But the gateway also calls the Python checker and logs where the two differ. This happens while the learner waits for the reply. So it adds waiting time, even though Python does not choose what is shown.

Every reply is logged with the route it took. There is also a fourth route, called disabled. On it, as on the shadow and fallback routes, the answer comes from the local check. These logs are how anyone can tell afterwards.

Calling Python adds waiting time. The client, which is the code that makes the call, has two time limits. One is for making the connection, and one is for the whole request. It also tries again only a limited number of times. So the total wait can include a health check and several tries.

How I know it works

Tests cover the LMS · LMS AI Core · The AI serviceKey-only accessEvery request to the service’s main web addresses, the ones with a version number, must carry an access key. If no key has been set up, the service refuses the request. Its public documentation pages are switched off.See it in the LMS build the client sends to prove it is allowed to call, a retry after a server error, and a time-out. They also cover a live Python check, a health check that fails, and the differences logged on the shadow route. The client only checks that a good response can be read as a list. It does not check the full shape of the response.