Clock icon with cross mark to symbolize automatic late penalties in CodeGrade's code learning platform.
October 15, 2025

Automatically deduct late penalties in CodeGrade

In 30 seconds...

Learn how to set up automatic penalties for late submissions in CodeGrade, making your grading more transparent and efficient.

Late submissions are a reality in most courses, and manually applying penalties can be tedious and inconsistent. With CodeGrade AutoTest, you can fully automate late point deductions using a small script and the built-in rubric system.

This guide walks you through setting up a penalty system that deducts 1 point per day late, up to a maximum of 10 points.

How It Works

Each submission in CodeGrade includes:

  • submitted_at: When the student submitted the work.
  • deadline: The assigned due date (automatically stored per assignment or per student).

Using this metadata, we’ll:

  1. Compare the submission time to the deadline.
  2. Calculate how many full days late the submission was.
  3. Deduct 1 point per day late.
  4. Apply that deduction to the rubric via AutoTest.

Step 1: Create a Rubric Category

Go to your assignment settings > Rubric and create a continuous rubric category to handle late penalties:

  • Name: Late Penalty
  • Minimum Points: -10
  • Maximum Points: 0

This allows up to 10 points to be deducted automatically, without any manual grading required.

Step 2: Add a Hidden Custom Test Block

Now go to the AutoTest Test, and follow these steps:

1. Add a Connect Rubric Block: Link it to the Late Penalty rubric category you created.

2. Inside it, add a Hide Config Block: This prevents students from seeing the test script output or logic.

3. Inside that, add a Custom Test Block: Use the script below to calculate the late penalty and output it in a format CodeGrade Custom Test understands.

Script 

-!- CODE language-py -!-#!/bin/bash
python3 <<EOF
import os
import json
import math
from datetime import datetime, timedelta

ONE_DAY = timedelta(days=1)

# Load submission info
cg_info = json.loads(os.environ["CG_INFO"])
submitted_at = datetime.fromisoformat(cg_info["submitted_at"].replace("Z", "+00:00"))
deadline = datetime.fromisoformat(cg_info["deadline"].replace("Z", "+00:00"))

# Calculate how many days late
days_late = math.ceil((submitted_at - deadline) / ONE_DAY)

# Determine score
if days_late <= 0:
    print("Submitted on time")
    print('{ "tag": "points", "points": "1" }', file=open(3, "w"))
elif days_late <= 10:
    print(f"{days_late} day(s) late")
    score = 1 - days_late / 10
    print(f'{{ "tag": "points", "points": "{score}" }}', file=open(3, "w"))
else:
    print("Very late, maximum penalty")
    print('{ "tag": "points", "points": "0" }', file=open(3, "w"))
EOF

This setup ensures that late penalties are applied automatically, fairly, and invisibly, saving time for instructors and ensuring consistency for students.

You can use this configuration as a starting point and customize it to match your course policies. For example:

  • Add a grace period before penalties begin.
  • Reduce the penalty rate (e.g., 0.5 points per day).
  • Apply maximum caps, weekend leniency, or per-student deadline overrides.

Click here for an overview of custom test blocks in CodeGrade.

Do you have more ideas for custom testing? Contact support@codegrade.com today!

‍

Discover the benefits of automatic grading!

Continue reading

What is a teacher for when AI writes the code?

When AI writes the code, teachers judge the thinking behind it. What the research shows and four things to try in your intro programming course.

Smarter Jupyter Notebook Setup in CodeGrade: Using AI to Draft Your Notebook Checks

Use AI to draft Jupyter Notebook checks in CodeGrade: three prompts for assertion cells, the JSON cell trick, and hardening checks for fair autograding.

Snowball Miracle: A Terminal, a Smarter AI Assistant, and Tighter Exam Controls

CodeGrade released Snowball Miracle on 21 August 2026. A terminal with tabs, an AI assistant that reads AutoTest results, tighter exam controls, API changes.

Sign up to our newsletter