{"id":"Gx2i2PUZXHk","title":"The Safety Layer That Runs Before Your AI Does","description":"Last video I walked through triage, deciding where each request goes once you know what's in it. This one covers what happens before that, because a few things need to run before you make any AI call at all.\n\nI'm Joe, building an AI product in public. \n\nEvery interaction is a turn. You go, the AI goes, back and forth. The user's turn determines everything downstream, and it can arrive as text, voice, a camera picture, or a file upload. If your product touches health information, that turn needs a safety layer before it goes anywhere.\n\nThe reason is latency. Any model call means waiting, even through private inference, even on a solid connection. A local model on a phone right now isn't fast or capable enough to be your first line either. So the safety layer scans for emergency lexicon locally, with a small on-device model doing a secondary check, and if something looks like it might warrant poison control or 911 the user gets prompted immediately and decides for themselves. The goal is to surface the option without manufacturing anxiety.\n\nAfter that comes local triage. On iOS there's an Apple on-device model that can handle a first pass fast. And often it turns out no model is needed at all. If you ask for your latest blood pressure reading, that data is already on your phone from Apple Health or manual entry. It's a lookup. Sending it out to an outside system, even inside a trusted execution environment, adds parties to a problem that didn't have any.\n\nThat's the part I want to leave you with. Data safety isn't only encryption and TEEs, as important as those are. Sometimes the strongest privacy answer is asking where the data already lives and whether you can reach it without involving anyone else. Don't overengineer.\n\nChapters\n0:00 Picking up where triage left off\n0:19 Turns, and why the user's turn decides everything\n0:35 Chat, voice, camera, file upload\n0:53 Why the safety layer has to run first\n1:24 Emergency lexicon and the local model check\n2:08 Local triage with an on-device model\n2:48 If the data is already on the phone, don't send it\n3:32 Privacy is also about where data lives\n3:49 When it does need to escalate\n4:06 Can the model reliably do what you're asking\n\nI'm documenting this whole build. Follow along and leave questions in the comments.\n\n#BuildInPublic #PrivacyByDesign #OnDeviceAI #HealthTech #AIEngineering","channel_name":"NEAR DevHub","published_at":"2026-08-14T00:00:00.000Z","thumbnail_url":"https://img.youtube.com/vi/Gx2i2PUZXHk/hqdefault.jpg","transcript_text":"I'm Joe and I'm building in public. Previous video I talked about how triage is really important for when you're dealing with any kind of sensitive information, especially with AI. Before we even get to that triage though, today we're going to talk about how do you actually approach that first half of it of how is the user responding and what are we doing before we even get to triage. Building with AI, we talk about something called turns. And each one of those turns basically is like you and the AV going back and forth of I go, you go, I go, you go back and forth. And that user turn is going to determine what happens next. And that user turn can involve multiple different modes of actual communication. It could be through chat. It could be through voice. It could be through a camera picture. It could be through a file upload. There's all different things that could go on here as part of that. Now, if you're building something that involves especially health, there probably needs to be something what I would consider a safety layer. And that safety layer needs to happen before you even wait to make an AI call because what happens is as soon as I go to make a call, even if it's through private inference, there is still some latency that I have to have a decent internet connection. I have to actually make sure the app can go and process that information. Even if I'm using a local model, there it might be some delay, but even then, a local model right now on a phone is probably not the best for actually determining right away. So, we have this safety layer that is doing a couple different things. One, we are looking for emergency lexicon. So, anything that looks like was phrased or worded in a way that constitute an emergency, then we can actually have a small local model do a secondary check as well. If there is something that is possibly an emergencybased thing, so something that maybe would involve having to call poison control or 911, uh you can do that right away. Now, the benefit here though is you can prompt the user immediately and let them decide, is this something that I want to continue with or do I actually need help? Hopefully, you're not causing too much anxiety for that user though as well. From there, the design that I'm using is starting on first is a local triage, but we again we again can use some local models that can be very fast and very low latency in order to do some initial triaging. Here on iOS, there is an Apple ondevice model that we can we can now take again that lexicon that is being typed in or provided through voice or through a video or through a file upload. And now we can start to see, okay, here's our initial triage, especially with something with health or anything else that maybe is very private. If I have the information on the phone already, I don't need to send it out. Even if I know it's in a safe manner using a trusted execution environment, why would I send it off device? The example might be is let's say I go and I go into my app and I want to ask what was my latest blood pressure reading? Well, first off, where does that data live? that is going to live on my phone. Maybe came from my Apple Health or from some other app or maybe I put it in manually. And so that device is that information is already there. I don't there's no need to go send it off to an an outside AI system. I don't really need AI for this at all. I just need to do a lookup. And that's a really important piece of all of this. We don't want to overengineer for things as well. So data safety is not just about using, you know, private and encrypted and trusted execution environments. That's all great and super important, but sometimes the best answer for user privacy and security is simply where does the data live and can I access it right now without adding any other parties into this? Then from there, if we can't solve it locally and it is something that then needs to be escalated in some form, whether it is private health information or not, we can then go into our full triage mode, which I talked about in a previous video. If you're using any private information of any kind of product, whether it is through a financial app, health, whatever it might be, you need to make sure that whatever is being asked of the AI is something that it can actually do. you know, is the AI actually trained well enough to actually be able to answer those questions? Is it going to do it consistently? Is it going to do it reli reliably? You know, what does that start to look like for an end user? Hopefully, this gave you some insights into how to actually start to build with AI. And this is something that I'm going to continue to show you. So, follow along on building in public and building with AI.","transcript_synced_at":"2026-11-03T03:47:32.806Z","segments":[{"start_seconds":2,"text":"I'm Joe and I'm building in public.","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=2s"},{"start_seconds":4,"text":"Previous video I talked about how triage is really important for when you're dealing with any kind of sensitive information, especially with AI. Before","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=4s"},{"start_seconds":11,"text":"we even get to that triage though, today we're going to talk about how do you actually approach that first half of it of how is the user responding and what","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=11s"},{"start_seconds":19,"text":"are we doing before we even get to triage. Building with AI, we talk about something called turns. And each one of those turns basically is like you and","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=19s"},{"start_seconds":27,"text":"the AV going back and forth of I go, you go, I go, you go back and forth. And that user turn is going to determine","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=27s"},{"start_seconds":35,"text":"what happens next. And that user turn can involve multiple different modes of actual communication. It could be through chat. It could be through voice.","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=35s"},{"start_seconds":45,"text":"It could be through a camera picture. It could be through a file upload. There's all different things that could go on here as part of that. Now, if you're","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=45s"},{"start_seconds":53,"text":"building something that involves especially health, there probably needs to be something what I would consider a safety layer. And that safety layer","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=53s"},{"start_seconds":61,"text":"needs to happen before you even wait to make an AI call because what happens is as soon as I go to make a call, even if it's through private inference, there is","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=61s"},{"start_seconds":69,"text":"still some latency that I have to have a decent internet connection. I have to actually make sure the app can go and process that information. Even if I'm","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=69s"},{"start_seconds":78,"text":"using a local model, there it might be some delay, but even then, a local model right now on a phone is probably not the","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=78s"},{"start_seconds":84,"text":"best for actually determining right away. So, we have this safety layer that is doing a couple different things. One, we are looking for emergency lexicon.","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=84s"},{"start_seconds":95,"text":"So, anything that looks like was phrased or worded in a way that constitute an emergency, then we can actually have a small local model do a secondary check","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=95s"},{"start_seconds":104,"text":"as well. If there is something that is possibly an emergencybased thing, so something that maybe would involve","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=104s"},{"start_seconds":110,"text":"having to call poison control or 911, uh you can do that right away. Now, the benefit here though is you can prompt","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=110s"},{"start_seconds":120,"text":"the user immediately and let them decide, is this something that I want to continue with or do I actually need help? Hopefully, you're not causing too","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=120s"},{"start_seconds":128,"text":"much anxiety for that user though as well. From there, the design that I'm using is starting on first is a local","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=128s"},{"start_seconds":135,"text":"triage, but we again we again can use some local models that can be very fast and very low latency in order to do some","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=135s"},{"start_seconds":143,"text":"initial triaging. Here on iOS, there is an Apple ondevice model that we can we can now take again that lexicon that is","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=143s"},{"start_seconds":152,"text":"being typed in or provided through voice or through a video or through a file upload. And now we can start to see,","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=152s"},{"start_seconds":160,"text":"okay, here's our initial triage, especially with something with health or anything else that maybe is very private. If I have the information on","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=160s"},{"start_seconds":168,"text":"the phone already, I don't need to send it out. Even if I know it's in a safe manner using a trusted execution environment, why would I send it off","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=168s"},{"start_seconds":176,"text":"device? The example might be is let's say I go and I go into my app and I want to ask what was my latest blood pressure","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=176s"},{"start_seconds":184,"text":"reading? Well, first off, where does that data live? that is going to live on my phone. Maybe came from my Apple Health or from some other app or maybe I","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=184s"},{"start_seconds":193,"text":"put it in manually. And so that device is that information is already there. I don't there's no need to go send it off","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=193s"},{"start_seconds":200,"text":"to an an outside AI system. I don't really need AI for this at all. I just need to do a lookup. And that's a really","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=200s"},{"start_seconds":207,"text":"important piece of all of this. We don't want to overengineer for things as well.","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=207s"},{"start_seconds":212,"text":"So data safety is not just about using, you know, private and encrypted and trusted execution environments. That's all great and super important, but","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=212s"},{"start_seconds":221,"text":"sometimes the best answer for user privacy and security is simply where does the data live and can I access it right now without adding any other","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=221s"},{"start_seconds":229,"text":"parties into this? Then from there, if we can't solve it locally and it is something that then needs to be escalated in some form, whether it is","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=229s"},{"start_seconds":238,"text":"private health information or not, we can then go into our full triage mode, which I talked about in a previous video. If you're using any private","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=238s"},{"start_seconds":246,"text":"information of any kind of product, whether it is through a financial app, health, whatever it might be, you need to make sure that whatever is being","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=246s"},{"start_seconds":254,"text":"asked of the AI is something that it can actually do. you know, is the AI actually trained well enough to actually be able to answer those questions? Is it","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=254s"},{"start_seconds":261,"text":"going to do it consistently? Is it going to do it reli reliably? You know, what does that start to look like for an end user? Hopefully, this gave you some insights into how to actually start to","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=261s"},{"start_seconds":270,"text":"build with AI. And this is something that I'm going to continue to show you.","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=270s"},{"start_seconds":274,"text":"So, follow along on building in public and building with AI.","url":"https://www.youtube.com/watch?v=Gx2i2PUZXHk&t=274s"}],"youtube_url":"https://youtube.com/watch?v=Gx2i2PUZXHk","url":"https://near-pedia.xyz/videos/Gx2i2PUZXHk"}