5 Rules To Give Your LLM To Avoid Sloppy Code

5 Rules To Give Your LLM To Avoid Sloppy Code by @thelogicaldude on 3Speak

What's happening everyone? In today's video I am talking about my 5 rules that I give all my LLMs to get production level code and not a bunch of AI slop. Here is a sample system prompt you can giv...

Tags: #development #llm #developer #rules #instructions #video #education #aiagent #prompts

Transcript

What's going on, everybody? It's your boy, The Logical Dude, sitting in the labs, and working with some AI, trying to get my own personal site up and running for my new services that I'm going to be offering. And just going through my processes and thought about a video I really wanted to make for you guys, because we've all been working with AI. If you haven't yet, well, then you're one of those haters. But... If you've been testing this out at all, you know that you can build stuff, it can code, but the stuff that it builds may be some sloppy garbage, right? The term AI slop really kind of earned its title. You know, let's all agree on that. All right, this stuff is not super intelligence right now. I hate to break it to certain Orange Man, but, you know, it's not super intelligence, it's still very much artificial, and you have to guide this stuff. You have to be the foreman. And this is where it kind of helps knowing coding and knowing how development works, even though if you're not a developer, you kind of need to know how stuff works in a way, because you have to be able to direct this stuff, right? All right, so I'm going to give you my five rules. Thumbnail shot. I'm going to give you my five rules on... What I do, and the guidelines that I give to my LLMs, it doesn't matter if I'm using Frontier or local models, it doesn't matter. I give all of them the same five rules. Now, I've kind of stripped these down and gotten some of my personal stuff out of there, and you can absolutely change this up to the way you want. But down in the description below, I've got a little code block there for you. So go and copy and paste that into your system prompt area and give your LLM these same rules. and you need to follow these rules as well to be able to get really good production level software, not a bunch of sloppy shack, right? So, let's get into it. Rule number one, you need to demand production grade quality up front. You got to tell the model, you know, write clean, modular, production ready code that follows best practices, solid principles where they apply. clear naming conventions, no spaghetti, crap, no hacks, no patchwork, no incomplete code snippets, none of that. It needs to actually work, all right? So one little tip too, and I do this with frontier models as well. Work in small batches, right? For your small models, you have to work in small batches. Period. Like, if you're not working in small bits with small models, you're going to get yourself messed up down the line. It'll start hallucinating like crazy, right? I mean, I'm sure you've seen the bigger models hallucinate like crazy, too. That's why you've got to work in small batches, not huge sessions where you've got a ton of context going. You know, I know you can get into like, you know, sessions like, hey, keep doing this, keep going, keep going, keep going. It's not good for it to keep going, keep going. You need to give it breaking points. get it to write you a handoff prompt to the next session, and then you take the handoff session, start a clean contact section, and then continue on. So that's, you know, that's really a great way to go because it can really get you screwed up if you don't. All right, so let's move along to rule number two. You got to force it to actually handle reality, right? So... improper inputs, you know, let's say edge cases, you know, basically you need to tell it to handle those things, errors, fallbacks, you know, failures, include validation, proper expectations, basic security, get all that stuff laid out. from the get-go and as it goes along so as it's right in functionality you need to make sure that it's going to be secure you know there's no memory leaks you need to make sure that it's you know properly written it connects in with the rest of the program that kind of thing and rule number three because that just leads right on into it always require runnable code any edits needs to be ran and needs to be validated, okay? Because the problem that you'll get into, and I've gotten into this quite a bit, is you'll give it a task, and it'll zoom through, and it codes up a bunch of stuff, and it's like, cool, done, this is what I did, blah, blah, blah, blah. Excuse me. Well, the problem is... is you see it running through and you see all these a okay syntax checks a okay syntax can be fine syntax can completely check out the code itself can look complete it can look like it's okay but it may not function worth of crap so that's why you need to force it to actually run the code and give you the proof that it is actually working. Because if not, you're going to get to the end of your project and nothing's going to work properly, and you're going to be like, what the heck, we got to go back and completely rebuild half the damn program, blah, blah, blah, because you didn't do this. So that's where, again, small batches come into play, but forcing it to check for, you know, check for errors, check for any kind of fault, you know, failures or anything that could happen. You know, if they're entering text, does that text leak anywhere? You know, that kind of stuff. You know, especially with security. Like, if you've got usernames and passwords, does that leak out anywhere? You need to make sure that everything's really nice and tight as you go along. All right. is you don't want to get to the end and have a bunch of sloppy chat, you know what I'm saying? All right, so rule number four is you need to really make it think before it touches any code. Kind of should be number one, but, you know, we've talked about this. Plan everything out first, so have, you know, like I said, a big level like Opus 5.5 or something. Come in and be your planner and architect. Get everything ran out, you know, planned out, everything in little phases and that kind of thing, and you are going to be A -OK. And then step five is stay inside the lines, man. Like, don't let it go off on rabbit trails. they'll tend to do that. Especially smaller local models, they'll tend to go off on all kind of little rabbit trails, trying to get stuff done. You need to make sure those things stay on task. That's why, you know, and I've got buddies that love to just, you know, set up a couple of, like, mixture of agents setups and just give each little agent a job and just go about their life and, you know, let it do its thing. Yeah, well. It doesn't always work. So you've got to stay on these things. Because if it goes off on a rabbit trail, it can go all the way around the rabbit trail, come back and tell you it's complete, but it didn't actually really touch the task that you wanted it to touch. It found something, it goes off on some trail and fixes something, but completely avoids what you told it to fix. So... Yeah, you got to stay on these things. So not only do you have to give it rules to stay inside the lanes, stay on track, stay focused. Hey, I'm ADHD as can be. Trust me, it's hard. But you've got to keep these things on track. If not, you're gonna get the sloppy chat. It's just, it just is what it is. So, those are essentially my five rules. And like I said, I have got this... down in the description below, in a nice little copy and paste prompt that you can personalize for yourself, so go and get that down there. So, but you gotta work these things, man. AI's an awesome tool, but it is not its own intelligence, it's not a super intelligence, and you have to be the visionary. Think about it like this. This is what I, this is what I like to say to, you know, even tell my LLMs. I'm Steve Jobs in this situation. You're the Wozniak. I'm the brain and the visionary. You are the engineer. You do all that work. I'm the human in the room. I'll do whatever I need to do to help you out. But you are the engineer. So you got to do this. You got to get all this done. So that's kind of like, that's the level that you need to be playing on. So you're a partner. It's a tool. It's going to work for you, but you've got to work with it. You can't just get it to work and then go off about your merry way because you're going to get some sloppy chat. Just is what it is. I love you guys. Until next time, I want y'all to be cool, be real, and always abide with yourself. and direct this AI, man, you got to be in control of the LLMs, not letting the LLMs be in control of you, because then we're living in Skynet World. Peace out, y'all.

More videos on 3Speak