liveBook · Manning

Shadow testing

As explained in Building Reliable AI Systems

Shadow testing evaluates a system or change alongside a live system without allowing the test results to affect user-facing behavior.

Shadow testing runs a candidate model alongside the production model on real queries. Candidate responses are logged for comparison but never shown to users, allowing evaluation without changing the live experience. section 10.5.3

A production-minded setup should:

  • Run candidate requests asynchronously so they do not add latency to user requests. section 10.5.3
  • Budget for roughly doubled model costs during evaluation, and limit tests to representative time windows. section 10.5.3
async def handle_query_with_shadow(question):                    
    production_response = production_model.generate(question)   #1

    asyncio.create_task(                                   #2
        shadow_test(question, production_response, candidate_model)
    )

    return production_response       #1                     

async def shadow_test(question, production_response,  #3
    candidate_model):           #3
    candidate_response = candidate_model.generate(question)    #3
  #3
    log_shadow_result({    #3
        "question": question,    #3
        "production_response": production_response,    #3
        "candidate_response": candidate_response,   #3
        "timestamp": datetime.now()    #3
    })

The Python sketch returns the production response immediately, then asynchronously runs the candidate model and logs both responses with a timestamp. section 10.5.3

How Building Reliable AI Systems covers it

How deep it goes
Implements asynchronous candidate requests and response logging, and notes cost and duration trade-offs.
Examples
Uses real user queries and an asynchronous Python sketch that logs production and candidate responses.
What it assumes
Assumes a production model is handling user queries alongside which a candidate can run.
What you can do after
Evaluate candidate models on production traffic and inform deployment decisions without exposing candidate outputs to users.
How it connects
Connects model evaluation with production monitoring and automated quality scoring.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Reliable AI Systems. The section links point to the parts of the book it draws on.