<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Abdur Rafay</title>
    <description>The latest articles on DEV Community by Abdur Rafay (@abdurrafay19).</description>
    <link>https://dev.to/abdurrafay19</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4171353%2F56742bbb-7b74-4252-99b4-07a62f18e1e3.jpg</url>
      <title>DEV Community: Abdur Rafay</title>
      <link>https://dev.to/abdurrafay19</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abdurrafay19"/>
    <language>en</language>
    <item>
      <title>Building a Python tutor that gives hints without leaking answers, using a 3B local model</title>
      <dc:creator>Abdur Rafay</dc:creator>
      <pubDate>Mon, 19 Oct 2026 14:51:59 +0000</pubDate>
      <link>https://dev.to/abdurrafay19/building-a-python-tutor-that-gives-hints-without-leaking-answers-using-a-3b-local-model-4j16</link>
      <guid>https://dev.to/abdurrafay19/building-a-python-tutor-that-gives-hints-without-leaking-answers-using-a-3b-local-model-4j16</guid>
      <description>&lt;p&gt;Hint Tutor is a tool for intro Python courses. A student submits broken code, and it returns a hint that points at the bug without giving the fix. It runs fully offline on a 3B parameter model through Ollama.&lt;/p&gt;

&lt;p&gt;Repo: &lt;a href="https://github.com/Abdurrafay19/hint_tutor" rel="noopener noreferrer"&gt;https://github.com/Abdurrafay19/hint_tutor&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem
&lt;/h2&gt;

&lt;p&gt;A TA with hundreds of lab submissions can't write a personal hint for each one. ChatGPT-style tools fail in two ways: they invent bugs that don't exist, or they paste the corrected code, which skips the learning.&lt;/p&gt;

&lt;p&gt;My approach was to stop trusting the model with anything it can't be checked on.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tests decide, the model explains
&lt;/h2&gt;

&lt;p&gt;Unit tests run first and decide whether the code is wrong. The model is only called after a test fails, and only to explain why.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Syntax error: Python's &lt;code&gt;compile()&lt;/code&gt; catches it and the pipeline returns the compiler's line number. No model call.&lt;/li&gt;
&lt;li&gt;All tests pass: success message. No model call.&lt;/li&gt;
&lt;li&gt;Assertion failure: the model gets the failing input, expected output, actual output, and numbered source.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Student code runs in a separate interpreter (&lt;code&gt;python -I&lt;/code&gt;) with a per-test timeout, so an infinite loop or runaway recursion can't freeze the app. This is not an OS-level sandbox, and the README says so.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three stages
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Stage 1, fault localization.&lt;/strong&gt; Ollama's structured output forces the model to return JSON:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "line": 3,
  "bug_type": "off_by_one",
  "reason": "The range excludes n because range stop values are non-inclusive."
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Temperature is 0.0 here so the output is stable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stage 2, hint drafting.&lt;/strong&gt; The model writes 2 to 3 sentences that point at the diagnosed line and end with a question. Temperature is 0.3. The prompt forbids code blocks and replacement expressions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stage 3, the Answer-Leak Guard.&lt;/strong&gt; Telling a small model "don't leak the answer" is not enough, so the guard checks every hint against the reference solution:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Reject code fences and executable statements (&lt;code&gt;def&lt;/code&gt;, &lt;code&gt;return&lt;/code&gt;, &lt;code&gt;for&lt;/code&gt;, &lt;code&gt;while&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Reject any normalized line that matches a line in the reference fix.&lt;/li&gt;
&lt;li&gt;For small diffs (under 5 lines), extract the added tokens, such as &lt;code&gt;n + 1&lt;/code&gt; or &lt;code&gt;&amp;lt;=&lt;/code&gt;, and reject hints that contain them.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A rejected draft triggers a retry with generic reasons only, so the fix never enters the prompt. After 3 failed attempts, the tool returns a fixed template: "Look at line N. Trace the failing input by hand and compare each step to what you expect."&lt;/p&gt;

&lt;p&gt;Example: on &lt;code&gt;sum_to_n&lt;/code&gt; with &lt;code&gt;range(1, n)&lt;/code&gt;, the first draft contained a literal &lt;code&gt;+ 1&lt;/code&gt;. The guard rejected it. The second draft asked what values &lt;code&gt;range&lt;/code&gt; visits for &lt;code&gt;sum_to_n(1)&lt;/code&gt;, and it passed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Measured results
&lt;/h2&gt;

&lt;p&gt;I evaluated on 50 cases: 42 AST mutants (swapped comparisons, changed operators, shifted constants) across 7 assignments, plus 8 hand-written structural bugs. Hardware was a Ryzen 5 5600H with 16 GB RAM, CPU only.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Metric&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Exact line diagnosis&lt;/td&gt;
&lt;td&gt;60% (30/50)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Within 1 line&lt;/td&gt;
&lt;td&gt;74% (37/50)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bug type match&lt;/td&gt;
&lt;td&gt;42% (21/50)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;First draft rejected by guard&lt;/td&gt;
&lt;td&gt;36% (18/50)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Fell back to the template&lt;/td&gt;
&lt;td&gt;22% (11/50)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Median latency, diagnosis / hint&lt;/td&gt;
&lt;td&gt;0.76 s / 0.79 s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The bug type score is the weakest. A 3B model finds the right region more often than it names the right category. The guard rejected more than a third of first drafts, which is the reason it exists.&lt;/p&gt;

&lt;h2&gt;
  
  
  Limits
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The benchmark is mostly synthetic. Real student bugs often combine two errors, and I haven't tested that.&lt;/li&gt;
&lt;li&gt;The guard blocks code and tokens, not English paraphrases like "increase the stop value by one." A hand audit of 50 hints found 20% were semantic paraphrases of the fix. 68% were clean guiding hints and 12% were harmless misdiagnoses.&lt;/li&gt;
&lt;li&gt;It only handles single-file scripts under 150 lines with no &lt;code&gt;input()&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Contributing
&lt;/h2&gt;

&lt;p&gt;The repo is MIT licensed with 29 unit tests that run in under 2 seconds without Ollama. The limits above are the open work: compound-bug test cases, paraphrase-leak detection, more assignments, and stronger execution isolation.&lt;/p&gt;

</description>
      <category>hacktoberfest</category>
      <category>ai</category>
      <category>python</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
